Click to See Complete Forum and Search --> : Cannot static linkage with CxImage


CBasicNet
August 31st, 2003, 10:33 PM
Hi guys,

I have made a "picture to ASCII" converter. I have a problem here; I cannot "Use MFC in a static Library", I can only link dynamically. I need to link statically as I want to distribute my program to my friends. To know more, please click on the link in my signature.

I use the CxImage from
here (http://www.codeproject.com/bitmap/cximage.asp)

These are the linkage errors and warnings I have,

AsciiArt error LNK2005: _fclose already defined in libcmt.lib(fclose.obj)
AsciiArt error LNK2005: _fread already defined in libcmt.lib(fread.obj)
AsciiArt error LNK2005: _fwrite already defined in libcmt.lib(fwrite.obj)
AsciiArt error LNK2005: _fseek already defined in libcmt.lib(fseek.obj)
AsciiArt error LNK2005: _ftell already defined in libcmt.lib(ftell.obj)
AsciiArt error LNK2005: _fflush already defined in libcmt.lib(fflush.obj)
AsciiArt error LNK2005: _free already defined in libcmt.lib(free.obj)
AsciiArt error LNK2005: _malloc already defined in libcmt.lib(malloc.obj)
AsciiArt error LNK2005: _realloc already defined in libcmt.lib(realloc.obj)
AsciiArt error LNK2005: _strncpy already defined in libcmt.lib(strncpy.obj)
AsciiArt error LNK2005: _calloc already defined in libcmt.lib(calloc.obj)
AsciiArt error LNK2005: _sprintf already defined in libcmt.lib(sprintf.obj)
AsciiArt error LNK2005: _strncmp already defined in libcmt.lib(strncmp.obj)
AsciiArt error LNK2005: _isprint already defined in libcmt.lib(_ctype.obj)
AsciiArt error LNK2005: _memmove already defined in libcmt.lib(memmove.obj)
AsciiArt error LNK2005: _abort already defined in libcmt.lib(abort.obj)
.....
AsciiArt warning LNK4006: _fclose already defined in libc.lib(fclose.obj); second definition ignored
AsciiArt warning LNK4006: _fread already defined in libc.lib(fread.obj); second definition ignored
AsciiArt warning LNK4006: _fwrite already defined in libc.lib(fwrite.obj); second definition ignored
AsciiArt warning LNK4006: _fseek already defined in libc.lib(fseek.obj); second definition ignored
AsciiArt warning LNK4006: _ftell already defined in libc.lib(ftell.obj); second definition ignored
AsciiArt warning LNK4006: _fflush already defined in libc.lib(fflush.obj); second definition ignored
AsciiArt warning LNK4006: _free already defined in libc.lib(free.obj); second definition ignored
AsciiArt warning LNK4006: _malloc already defined in libc.lib(malloc.obj); second definition ignored
AsciiArt warning LNK4006: _realloc already defined in libc.lib(realloc.obj); second definition ignored
AsciiArt warning LNK4006: _strncpy already defined in libc.lib(strncpy.obj); second definition ignored
AsciiArt warning LNK4006: _calloc already defined in libc.lib(calloc.obj); second definition ignored
AsciiArt warning LNK4006: _sprintf already defined in libc.lib(sprintf.obj); second definition ignored
AsciiArt warning LNK4006: _isprint already defined in libc.lib(_ctype.obj); second definition ignored
AsciiArt warning LNK4006: _memmove already defined in libc.lib(memmove.obj); second definition ignored
AsciiArt warning LNK4006: _abort already defined in libc.lib(abort.obj); second definition ignored
........
There are more but I think they are the same. I tried to set the libraries from Multithreaded to Single threaded, I still get the same errors.

However, when I linked dynamically, eveything went smoothly.

CBasicNet
August 31st, 2003, 10:48 PM
To explain further, I use the static libs of CxImage when I link statically or dynamically. I'm very sure they are static libs, not import lib, as I used dependency walker to check if it uses any non-standard DLLs.

Any help would be appreciated.

Thank you.

Runt888
August 31st, 2003, 11:01 PM
I've used CxImage before. The projects that you can download have a few problems with them. First you should make sure all of them are set to use the single threaded or multithreaded libraries, not a mixture of both. Then compile the CxImage project, not CxImageCrtDll or CxImageMfcDll. This will create a library that you can link to statically. Let me know if you get it to work. I can email you the libraries if you need them.

Kelly

CBasicNet
August 31st, 2003, 11:19 PM
Hi Kelly,

The situation is this I can link with the static libs of CxImage but it is dynamically linkage to MFC.(Strange, isn't it?) I found this out when I changed from static linkage to dynamic linkage, everything suddenly builds just fine. That means my program uses hybrid of static libs(CxImage) and DLLs of MFC.

Runt888
August 31st, 2003, 11:24 PM
I had a lot of similar problems when using CxImage. I set the compiler to ignore the libraries that had the conflicts, and that allowed it to compile. However, when I changed the libraries to use the same version of the C runtime libraries, it solved all of my problems. I don't use MFC, so if it really is a problem with that, I don't know what to tell you.

Kelly

CBasicNet
August 31st, 2003, 11:28 PM
I can rewrite in Win32 if I'm desperate. But the errors are about (as you can see in the first post) C functions. And can you tell me how to set in VC to use the same version of the C runtime libraries?:)

Runt888
September 1st, 2003, 12:01 AM
Sure, it's pretty easy. Open the CxImage workspace with all the libraries. Select Project->Properties. Select each project in the list and make sure they all have the same settings for the MFC library (Not Using MFC for a static library). Then select the C/C++ tab and select Code Generation in the combo box. In the Use Run-time Library combo box, make sure all of them are set to Single-Threaded (or multi threaded depending on your settings). Then remake all the libraries and try to recompile your project. Hope it works.

Kelly

CBasicNet
September 1st, 2003, 04:35 AM
Thanks Kelly. It works! Thanks again!:)

It turns out that CxImage static lib projects, in my case, are not set uniformly the same; some uses MFC shared library while some uses MFC static library.

:D

Runt888
September 1st, 2003, 02:02 PM
Glad to hear it. I spent way too much time debugging that same problem. Probably easier than writing my own image library though:D.

Kelly