0

I have a VS2012 project using the debug version of the MD built libraries (PocoFoundationmdd.lib etc.). #POCO_STATIC is defined - and all is good.

When compiling in Release mode, I am using the release version of the same libraries (PocoFoundationmd.lib) - but VS2012 then suddenly refuses to link and asks for the MT version instead (PocoFoundationmt.lib )

error LNK1104: cannot open file 'PocoFoundationmt.lib'  

What's causing POCO/VS to look for the MT version instead of the MD version in Release mode? Any ideas?

Here's the linker command that VS2012 uses in DEBUG mode (which works)

/OUT:"C:\xxx...\xxx.dll" /MANIFEST /NXCOMPAT /PDB:"C:\xxx...\xxx.pdb" /DYNAMICBASE "ssleay32.lib" "libeay32.lib" "cpprest120d_2_8.lib" "log4cppD.lib" "winhttp.lib" "Crypt32.lib" "Bcrypt.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"C:\xxx...\xxx.lib" /DEBUG /DLL /MACHINE:X86 /INCREMENTAL /PGD:"C:\xxx...\xxx.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\xxx.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"..\libs\Poco\Debug" /TLBID:1  

.. and here's the linker command for RELEASE mode (which doesn't work)

/OUT:"C:\xxx...\xxx.dll" /MANIFEST /LTCG /NXCOMPAT /PDB:"C:\xxx...\xxx.pdb" /DYNAMICBASE "ssleay32.lib" "libeay32.lib" "cpprest120_2_8.lib" "log4cppLIB.lib" "winhttp.lib" "Crypt32.lib" "Bcrypt.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"C:\xxx...\xxx.lib" /DEBUG /DLL /MACHINE:X86 /OPT:REF /SAFESEH /INCREMENTAL:NO /PGD:"C:\xxx...\xxx.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Release\xxx.dll.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"..\libs\Poco\Release" /TLBID:1 

3 Answers3

1

Hard to tell without seeing what your compile command line looks like. Perhaps you define POCO_STATIC in one of your headers? That define may be encountered after Foundation.h has already been included and linking will go according to this logic. There may be differences in includes between release and debug. Or, you may actually be linking with mtd.lib in debug and have built `PocoFoundationmtd.lib but not PocoFoundationmt.lib, so release build can't find it.

Reading this answer may help.

Community
  • 1
  • 1
Alex
  • 5,159
  • 4
  • 25
  • 33
1

Adding POCO_STATIC and _DLL to Preprocessor Definitions fixed it!

(I also recompiled all other LIBS in the same project to MD - since there was some MT libs in there.)

Thanks!

  • 1
    *Never* define `_DLL` yourself. It is a built-in macro and automatically defined when you use /MD. You are hiding a build bug, one that can cause very gritty linker errors and exceedingly nasty runtime errors. You have rock-hard evidence that some code is getting compiled with /MT, you'll have to find it. – Hans Passant Aug 14 '16 at 09:19
  • I think you are 100% right Hans. After going through all settings once more and making sure that all C++ > Code Generation > RunTime Library is set to /MD - it works without _DLL in preprocessor definitions. Must have been a /MT in there somewhere when I had these problems. – Njål Arne Gjermundshaug Aug 18 '16 at 08:52
-1

Libraries compiled in Debug Mode are often quite different from Release Mode libraries, for a number of reasons:

  • They could have error-handling/debugging messages that aren't visible to the compiler in Release
  • The Code Optimization differences between Debug and Release could be significant enough to prevent cross-compilation
  • There could be entire levels of functionality that differ between Debug and Release, under certain circumstances.

In general, unless you yourself specifically are in charge of generating those libraries, you'll need to grab separate versions for Debug and Release, and make sure your project is configured to grab the correct one for each configuration.

Xirema
  • 19,889
  • 4
  • 32
  • 68
  • @NjålArneGjermundshaug You might want to provide more of your source code, since simply saying "I'm defining `#POCO_STATIC`" doesn't necessarily indicate it's being used correctly. – Xirema Aug 11 '16 at 18:34
  • #define POCO_STATIC is included at the top of the cpp files that use POCO. The solution compiles and runs fine in DEBUG mode. My Release config is identical to the Debug - except that the POCO Release libs are included in the Library Directories - and not the Debug libs. POCO_STATIC is included in Preprocessor Definitions of both Debug and Release configurations. It compiles fine in debug - the linker looks up and uses the MDD version of the libs. In Release - the linker should use the MD version of the libs - but instead it insists on using the MT version for some reason. – Njål Arne Gjermundshaug Aug 11 '16 at 19:46