title: how to link with static mySQL C library with Visual Studio 2008?
body: <p>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 <a href="https://stackoverflow.com/questions/2637499/how-can-a-win32-app-plugin-load-its-dll-in-its-own-directory">how can a Win32 App plugin load its DLL in its own directory</a>)</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Whenever I switched to the static library in the linker additional dependency, I get the following errors (log at the end):</p>
  
  <p>1- about 40 duplicate symbols (e.g. <code>_toupper</code>) 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?</p>
  
  <pre><code>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)  
  </code></pre>
  
  <p>2- two warnings that <code>MSVCRT</code> and <code>LIBCMT</code> <code>conflicts with use of other libs</code>, with a suggestion to <code>use /NODEFAULTLIB:library:</code>. I don't understand that suggestion: what am I supposed to do and how?</p>
  
  <pre><code>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  
  </code></pre>
  
  <p>3- an external symbol is undefined: <code>_main</code>. So does that mean that the static mySQL lib (but not the DLL) references a <code>_main</code> symbol? For the sake of it, I tried to define an empty function named <code>_main()</code> in my code, with no difference.</p>
  
  <pre><code>LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main  
  </code></pre>
  
  <p>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.</p>
  
  <p>Here is the full set of errors:</p>
  
  <p>1>    Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\MSVCRT.lib:<br>
  1>    Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:<br>
  1>    Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\msvcprt.lib:<br>
  1>    Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:<br>
  1>LIBCMT.lib(setlocal.obj) : error LNK2005: _setlocale already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encoded_null already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(tolower.obj) : error LNK2005: _tolower already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter_noinfo already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(crtheap.obj) : error LNK2005: __malloc_crt already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(_file.obj) : error LNK2005: ___iob_func already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(winxfltr.obj) : error LNK2005: ___CppXcptFilter already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj)<br>
  1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj)<br>
  1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj)<br>
  1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj)<br>
  1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(winsig.obj) : error LNK2005: _signal already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(fflush.obj) : error LNK2005: _fflush already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(tzset.obj) : error LNK2005: __tzset already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(_ctype.obj) : error LNK2005: _isspace already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(_ctype.obj) : error LNK2005: _iscntrl already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(getenv.obj) : error LNK2005: _getenv already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(strnicmp.obj) : error LNK2005: __strnicmp already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(osfinfo.obj) : error LNK2005: __get_osfhandle already defined in MSVCRT.lib(MSVCR90.dll)<br>
  1>LIBCMT.lib(osfinfo.obj) : error LNK2005: __open_osfhandle already defined in MSVCRT.lib(MSVCR90.dll)<br>
  [...]<br>
  1>    Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\MSVCRT.lib:<br>
  1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _toupper already defined in LIBCMT.lib(toupper.obj)<br>
  1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _isalpha already defined in LIBCMT.lib(_ctype.obj)<br>
  1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _wcschr already defined in LIBCMT.lib(wcschr.obj)<br>
  1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _isdigit already defined in LIBCMT.lib(_ctype.obj)<br>
  1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _islower already defined in LIBCMT.lib(_ctype.obj)<br>
  1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: ___doserrno already defined in LIBCMT.lib(dosmap.obj)<br>
  1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _strftime already defined in LIBCMT.lib(strftime.obj)<br>
  1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _isupper already defined in LIBCMT.lib(_ctype.obj)<br>
  [...]<br>
  1>Finished searching libraries<br>
  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<br>
  1>Searching libraries<br>
  [...]<br>
  1>Finished searching libraries<br>
  1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library<br>
  1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library<br>
  1>LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main  </p>