views:

1897

answers:

1

I'm new to Visual Studio and Windows as a development platform, and I'm having troubles linking a static library from one 'Project' into an executable in another. The library builds without error, but linking bails after finding several STL template instantiations defined in the library.

For the purpose of this question, Project A builds a static library, which I then attempt to link with in Project B.

I'm hoping someone can point out what I'm missing here.

The build command line for Project A:

/Od <includes> /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_WIN32_WINNT=0x0501" /D "DEBUG" /D "WS4_WIN32" /D "AF" /D "_VC80_UPGRADE=0x0710" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /Wp64 /ZI /TP /wd4290 /errorReport:prompt

The build and link command lines for Project B:

/Od <includes> /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TP /wd4290 /errorReport:prompt  
/OUT:<exe name> /INCREMENTAL /NOLOGO /MANIFEST /MANIFESTFILE:"<exe name>.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:<pdb name> /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib  ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib <Project A Lib file>

When the linker runs, I get a ton of errors of the following form:

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "<some STL template instantiation>" (<mangled name>) already defined in <Project A>.lib(<some Project A object>.obj)

I think this is telling me that an STL instantiation defined in an object of my library is also defined in msvcprtd.lib. What's not clear to me is if I'm not building my static library correctly, or if my linker settings are wrong. I would appreciate any guidance on this.

+3  A: 

You have mismatching runtime libraries specified.

It is set to /MTd for project A and /MDd for project B.

  • /MTd - Multithreaded Debug
  • /MDd - Multithreaded Debug DLL
Soo Wei Tan
Thanks. That did the trick. A more careful inspection of the build configuration would have solved this.Would anyone care to elaborate on why that mismatch causes this specific error?
Adam
This link from MSDN explains this would occur.http://msdn.microsoft.com/en-us/library/6wtdswk0(VS.80).aspx
Soo Wei Tan