how to link with static mySQL C library with Visual Studio 2008?

Posted by Jean-Denis Muys on Stack Overflow See other posts from Stack Overflow or by Jean-Denis Muys
Published on 2010-05-17T23:00:51Z Indexed on 2010/05/17 23:10 UTC
Read the original article Hit count: 414

Filed under:
|
|

Hi,

My project is running fine, but its requirement for some DLLs means it cannot be simply dragged and dropped by the end user. The DLLs are not loaded when put side by side with my executable, because my executable is not an application, and its location is not in the few locations where Windows looks for DLL. I already asked a question about how to make their loading happen. None of the suggestions worked (see the question at http://stackoverflow.com/questions/2637499/how-can-a-win32-app-plugin-load-its-dll-in-its-own-directory)

So I am now exploring another way: get rid of the DLLs altogether, and link with static versions of them. This is failing for the last of those DLLs.

So I am at this point where all but one of the libraries are statically linked, and everything is fine. The last library is the standard C library for mySQL, aka Connector/C. The problem I have may or may not be related with that origin.

Whenever I switched to the static library in the linker additional dependency, I get the following errors (log at the end):

1- about 40 duplicate symbols (e.g. _toupper) mutually between LIBCMT.lib and MSVCRT.lib. Interestingly, I can't control the inclusion of these two libraries: they are from Visual Studio and automatically included. So why are these symbol duplicate when I include mySQL's static lib, but not its DLL?

Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\MSVCRT.lib:  
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:  
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\msvcprt.lib:  
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:  
LIBCMT.lib(setlocal.obj) : error LNK2005: _setlocale already defined in MSVCRT.lib(MSVCR90.dll)  

Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\MSVCRT.lib:  
MSVCRT.lib(MSVCR90.dll) : error LNK2005: _toupper already defined in LIBCMT.lib(toupper.obj)  

2- two warnings that MSVCRT and LIBCMT conflicts with use of other libs, with a suggestion to use /NODEFAULTLIB:library:. I don't understand that suggestion: what am I supposed to do and how?

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library  
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library  

3- an external symbol is undefined: _main. So does that mean that the static mySQL lib (but not the DLL) references a _main symbol? For the sake of it, I tried to define an empty function named _main() in my code, with no difference.

LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main  

As mentioned in my first question, my code is a port of a fully working Mac version of the code. Its a plugin for a host application that I don't control. The port currently works, albeit with installation issues due to that lone remaining DLL. As a Mac programmer I am rather disoriented with Visual Studio and Windows which I find confusing, poorly designed and documented, with error messages that are very difficult to grasp and act upon. So I will be very grateful for any help.

Here is the full set of errors:

1> Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\MSVCRT.lib:
1> Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:
1> Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\msvcprt.lib:
1> Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:
1>LIBCMT.lib(setlocal.obj) : error LNK2005: _setlocale already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encoded_null already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(tolower.obj) : error LNK2005: _tolower already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter_noinfo already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crtheap.obj) : error LNK2005: __malloc_crt already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(file.obj) : error LNK2005: __iob_func already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: _lock already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(winxfltr.obj) : error LNK2005: _
_CppXcptFilter already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(winsig.obj) : error LNK2005: _signal already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(fflush.obj) : error LNK2005: _fflush already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(tzset.obj) : error LNK2005: __tzset already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(_ctype.obj) : error LNK2005: _isspace already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(_ctype.obj) : error LNK2005: _iscntrl already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(getenv.obj) : error LNK2005: _getenv already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(strnicmp.obj) : error LNK2005: __strnicmp already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(osfinfo.obj) : error LNK2005: __get_osfhandle already defined in MSVCRT.lib(MSVCR90.dll)
1>LIBCMT.lib(osfinfo.obj) : error LNK2005: __open_osfhandle already defined in MSVCRT.lib(MSVCR90.dll)
[...]
1> Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\MSVCRT.lib:
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _toupper already defined in LIBCMT.lib(toupper.obj)
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _isalpha already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _wcschr already defined in LIBCMT.lib(wcschr.obj)
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _isdigit already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _islower already defined in LIBCMT.lib(ctype.obj)
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _
_doserrno already defined in LIBCMT.lib(dosmap.obj)
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _strftime already defined in LIBCMT.lib(strftime.obj)
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _isupper already defined in LIBCMT.lib(_ctype.obj)
[...]
1>Finished searching libraries
1> Creating library z:\PCdev\Test\RK_Demo_2004\plugins\Test.bundle\contents\windows\Test.lib and object z:\PCdev\Test\RK_Demo_2004\plugins\Test.bundle\contents\windows\Test.exp
1>Searching libraries
[...]
1>Finished searching libraries
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

© Stack Overflow or respective owner

Related posts about visual-studio-2008

Related posts about linking