Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NODEFAULTLIB nightmare in VS2010 C++ project: links fine in debug, can't find a consistent set of libraries in release

Overflowers!

I've been developing a statically-linked application using Visual Studio 2010 (well, it's cross-platform, but this is just a Windows issue).

I had few issues setting up the linking for the Debug configuration, so I didn't expect it would be hard to change it to make a Release configuration, but after an afternoon's work it's still eluding me. Trying various values for NODEFAULTLIB either get me "unresolved external symbol" errors or "already defined in" errors and sometimes both.

From my notes, I've tried NODEFAULTLIB-ing LIBCMT, MSVCRT, MSVCPRT, or none at all, with different results each time (see below for details).

Now, my Debug configuration uses /NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:MSVCPRTD and that works fine, so you'd think that /NODEFAULTLIB:MSVCRT /NODEFAULTLIB:MSVCPRT would work for the Release configuration. And the fact that it doesn't is a red flag for me...

I'm linking with several other libraries - I was pretty careful to systematically make sure that they were considered exactly the same when going from Debug to Release but could that conceivably be an issue, and if so how to track it down systematically?

Thanks for your gracious time!

In the Linker/Command Line property page, All Options is:

 /OUT:".\Release\SlowGold 8.exe" /NOLOGO "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:".\Release\SlowGold 8.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:".\Release\SlowGold 8.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /PGD:"C:\development\rec-vs\rec\projects\slow\Builds\VisualStudio2010\Release\SlowGold 8.pgd" /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE 

and Additional Options is:

/LIBPATH:..\\..\\..\\..\\externals\\rubberband\\win32\\ipp\\common ippacemerged.lib ippacmerged.lib ippcorel.lib ippsemerged.lib ippsmerged.lib ippsremerged.lib ippsrmerged.lib /LIBPATH:..\\..\\..\\..\\externals\\rubberband\\win32\\ipp\\release\\static rubberband-library.lib /LIBPATH:..\\..\\..\\..\\..\\glog\\Release libglog_static.lib /LIBPATH:..\\..\\..\\..\\..\\mpg123\\ports\\MSVC++\\2008\\Release libmpg123.lib /LIBPATH:..\\..\\..\\..\\..\\protobuf\\vsprojects\\Release libprotobuf.lib 

And here are some error messages for various /NODEFAULTLIB: values.

Best so far: /NODEFAULTLIB:LIBCMT

1>------ Build started: Project: Slow, Configuration: Release Win32 ------
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@_N@Z) already defined in libcpmt.lib(cerr.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>.\Release\SlowGold 8.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Another attempt with only /NODEFAULTLIB:MSVCRT

1>------ Build started: Project: Slow, Configuration: Release Win32 ------
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@_N@Z) already defined in libcpmt.lib(cerr.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp__strncat
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp__perror
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp___pclose
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl _open(char const *,int,int)" (__imp_?_open@@YAHPBDHH@Z)
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp___access
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp___popen
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp___wassert
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp__fdopen
1>OLDNAMES.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp__fdopen
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp__unlink
1>OLDNAMES.lib(unlink.obi) : error LNK2001: unresolved external symbol __imp__unlink
1>libglog_static.lib(utilities.obj) : error LNK2001: unresolved external symbol __imp___getpid
1>libglog_static.lib(port.obj) : error LNK2001: unresolved external symbol __imp___vsnprintf
1>libprotobuf.lib(message.obj) : error LNK2001: unresolved external symbol __imp__ldiv
1>libprotobuf.lib(descriptor.obj) : error LNK2001: unresolved external symbol __imp__ldiv
1>libprotobuf.lib(extension_set.obj) : error LNK2001: unresolved external symbol __imp__ldiv
1>libprotobuf.lib(common.obj) : error LNK2001: unresolved external symbol __imp___snprintf
1>libprotobuf.lib(strutil.obj) : error LNK2001: unresolved external symbol __imp___snprintf
1>OLDNAMES.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp___fdopen
1>OLDNAMES.lib(unlink.obi) : error LNK2001: unresolved external symbol __imp___unlink
1>.\Release\SlowGold 8.exe : fatal error LNK1120: 15 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Without /NODEFAULTLIB:

1>------ Build started: Project: Slow, Configuration: Release Win32 ------
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@_N@Z) already defined in libcpmt.lib(cerr.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __stricmp already defined in LIBCMT.lib(stricmp.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strerror_s already defined in LIBCMT.lib(strerror.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fflush already defined in LIBCMT.lib(fflush.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strtol already defined in LIBCMT.lib(strtol.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strrchr already defined in LIBCMT.lib(strrchr.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __write already defined in LIBCMT.lib(write.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __close already defined in LIBCMT.lib(close.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memmove already defined in LIBCMT.lib(memmove.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _printf already defined in LIBCMT.lib(printf.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fprintf already defined in LIBCMT.lib(fprintf.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _abort already defined in LIBCMT.lib(abort.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memchr already defined in LIBCMT.lib(memchr.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __strtoi64 already defined in LIBCMT.lib(strtoq.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __strtoui64 already defined in LIBCMT.lib(strtoq.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strtoul already defined in LIBCMT.lib(strtol.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __errno already defined in LIBCMT.lib(dosmap.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strerror already defined in LIBCMT.lib(strerror.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strchr already defined in LIBCMT.lib(strchr.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _sprintf already defined in LIBCMT.lib(sprintf.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strtod already defined in LIBCMT.lib(strtod.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strpbrk already defined in LIBCMT.lib(strpbrk.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __read already defined in LIBCMT.lib(read.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>.\Release\SlowGold 8.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
like image 909
Tom Swirly Avatar asked Jan 17 '12 00:01

Tom Swirly


1 Answers

Hans Passant provided me the key to the solution in his comments to my problem! If he'd come back and phrase them as an answer, I'd erase this and credit him...

As predicted, one of the third-party libraries was not set to /MT in release (but it was /MTd in debug) - changing that flag made it all work.

You find the option in Properties - C/C++ - Code Generation - Runtime Library

like image 111
Tom Swirly Avatar answered Oct 26 '22 22:10

Tom Swirly