<p>I'm building an application against some legacy, third party libraries, and having problems with the linking stage.  I'm trying to compile with Visual Studio 9.  My compile command is:</p>

<pre><code>cl -DNT40 -DPOMDLL -DCRTAPI1=_cdecl
-DCRTAPI2=cdecl -D_WIN32 -DWIN32 -DWIN32_LEAN_AND_MEAN -DWNT -DBYPASS_FLEX -D_INTEL=1 -DIPLIB=none -I. -I"D:\src\include" -I"C:\Program Files\Microsoft Visual Studio
9.0\VC\include" -c -nologo -EHsc -W1 -Ox -Oy- -MD mymain.c
</code></pre>

<p>The code compiles cleanly.  The link command is:</p>

<pre><code>link -debug -nologo -machine:IX86
-verbose:lib -subsystem:console mymain.obj wsock32.lib advapi32.lib
msvcrt.lib oldnames.lib kernel32.lib
winmm.lib [snip large list of
dependencies] D:\src\lib\app_main.obj
-out:mymain.exe
</code></pre>

<p>The errors that I'm getting are:</p>

<pre><code>app_main.obj : error LNK2019:
unresolved external symbol
"_\_declspec(dllimport) public: void
__thiscall std::locale::facet::_Register(void)"
(__imp_?_Register@facet@locale@std@@QAEXXZ)
referenced in function "class
std::ctype&lt;char&gt; const &amp; __cdecl
std::use_facet&lt;class std::ctype&lt;char&gt;
(class std::locale const &amp;)" (??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z)

app_main.obj : error LNK2019:
unresolved external symbol
"__declspec(dllimport)  public: static
unsigned int __cdecl
std::ctype&lt;char&gt;::_Getcat(class
std::locale::facet const * *)"
(__imp_?_Getcat@?$ctype@D@std@@SAIPAPBVfacet@locale@2@@Z)
referenced in function "class
std::ctype&lt;char&gt; const &amp; __cdecl
std::use_facet&lt;class std::ctype&lt;char&gt;
(class std::locale const &amp;)" (??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z)

app_main.obj : error LNK2019:
unresolved external symbol
"__declspec(dllimport)  public: static
unsigned int __cdecl
std::ctype&lt;unsigned
short&gt;::_Getcat(class
std::locale::facet const * *)"
(__imp_?_Getcat@?$ctype@G@std@@SAIPAPBVfacet@locale@2@@Z)
referenced in function "class
std::ctype&lt;unsigned short&gt; const &amp;
__cdecl std::use_facet&lt;class std::ctype&lt;unsigned short&gt; &gt;(class
std::locale const &amp;)"
(??$use_facet@V?$ctype@G@std@@@std@@YAABV?$ctype@G@0@ABVlocale@0@@Z)

mymain.exe : fatal error LNK1120: 3
unresolved externals
</code></pre>

<p>Notice that these errors are coming from the legacy code, not my code - app_main.obj is part of the legacy code, while mymain.c is my source.  I've done some searching around, and what that I've read says that this type of error is caused by a mismatch with the -MD switch between my code and the library that I'm linking to.  Since I'm dealing with legacy code, a solution has to come from my environment. It's been a long time since I've done C++ work, and even longer since I've used Visual Studio, so I'm hoping that this is just some ignorance on my part.  Any ideas on how to get these resolved?</p>

[{'answer_id': 23212, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 2, 'selected': False, 'text': "<p>These are standard library references. Make sure that all libraries (including the standard library) are using the <em>same</em> linkage. E.g. you can't link statically while linking the standard lib dynamically. The same goes for the threading model used. Take special care that you and the 3rd party library use the same linkage options.</p>\n\n<p>This can be a real pain in the *ss.</p>\n"}, {'answer_id': 26180, 'author': 'Matt McMinn', 'author_id': 1322, 'author_profile': 'https://Stackoverflow.com/users/1322', 'pm_score': -1, 'selected': True, 'text': "<p>After trying to get this stuff to compile under VS 2008, I tried earlier versions of VS - 2005 worked with warnings, and 2003 just worked.  I double checked the linkages and couldn't find any problems, so either I just couldn't find it, or that wasn't the problem.  </p>\n\n<p>So to reiterate, downgrading to VS 2003 fixed it.</p>\n"}, {'answer_id': 26217, 'author': 'jan', 'author_id': 1163, 'author_profile': 'https://Stackoverflow.com/users/1163', 'pm_score': 2, 'selected': False, 'text': '<p>Check this on <a href="http://msdn.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx" rel="nofollow noreferrer" title="MSDN">MSDN</a>:</p>\n\n<ul>\n<li>/MD Causes your application to use the multithread- and DLL-specific version of the run-time library.</li>\n<li>/MT  Causes your application to use the multithread, static version of the run-time library.</li>\n</ul>\n\n<p>Note:  "... so that the linker will use LIBCMT.lib to resolve external symbols"</p>\n\n<p>So you\'ll need a different set of libraries.</p>\n\n<p>How I went about finding out which libraries to link:</p>\n\n<ol>\n<li>Find a configuration that <em>does</em> link, and add /verbose option.</li>\n<li>Pipe the output to a text file.</li>\n<li>Try the configuration that <em>doesn\'t</em> link.</li>\n<li>Look in the verbose output from step 2 for the symbols that are unresolved ("_declspec(dllimport) public: void thiscall std::locale::facet::Register(void)" in your case) and find the used libraries.</li>\n<li>Add those libraries to the list of libraries you\'re linking to.</li>\n</ol>\n\n<p>Old skool but it <a href="https://stackoverflow.com/questions/9570/what-libraries-do-i-need-to-link-my-mixed-mode-application-to">worked</a> for me.</p>\n\n<p>Jan</p>\n'}, {'answer_id': 44886, 'author': 'Henk', 'author_id': 4613, 'author_profile': 'https://Stackoverflow.com/users/4613', 'pm_score': 2, 'selected': False, 'text': '<p>If you still wish to get the project to compile using VS2008 (or in the future) I can suggest using a binary editor to view the object file in question <em>mainapp.obj</em>.</p>\n\n<p>Here is an example from a small project of mine.</p>\n\n<p>The zdbException.obj contains the following excerpt</p>\n\n<pre><code>DEFAULTLIB:"libc\npmtd" /DEFAULTLI\nB:"uuid.lib" /DE\nFAULTLIB:"uuid.l\nib" /include:?id\n@?$num_put@DV?$o\nstreambuf_iterat\nor@DU?$char_trai\nts@D@std@@@std@@\n@std@@2V0locale@\n2@A /include:?id\n@?$numpunct@D@st\nd@@2V0locale@2@A\n /DEFAULTLIB:"LI\nBCMTD" /DEFAULTL\nIB:"OLDNAMES" /E\nDITANDCONTINUE \n</code></pre>\n\n<p>Note the entry <strong>/DEFAULTLIB:"LIBCMTD"</strong>. This indicates the object file was compiled with the static c run-time multi-threaded debug.</p>\n\n<p>There is also the possibility that the functions referenced in the obj are deprecated in the standard run-time lib shipped with VS2008.</p>\n'}]
['https://Stackoverflow.com/questions/23209', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1322/']