Huge Amount of Linker Issues with Release Build Only - c++

Anyone have idea on this? Linker errors are way out of my wheelhouse, especially ones like this.
Is there any more info I should include?
1>Linking...
1>freeglut_static.lib(freeglut_window.obj) : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __heap_alloc already defined in LIBCMT.lib(malloc.obj)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __recalloc already defined in LIBCMT.lib(recalloc.obj)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __msize already defined in LIBCMT.lib(msize.obj)
1>LIBCMTD.lib(malloc.obj) : error LNK2005: _V6_HeapAlloc already defined in LIBCMT.lib(malloc.obj)
1>LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in LIBCMT.lib(dbghook.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_pHeaderDefer already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: __get_sbh_threshold already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: __set_sbh_threshold already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: __set_amblksiz already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: __get_amblksiz already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_heap_init already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_find_block already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_free_block already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_block already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_new_region already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_alloc_new_group already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_resize_block already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_heapmin already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(sbheap.obj) : error LNK2005: ___sbh_heap_check already defined in LIBCMT.lib(sbheap.obj)
1>LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype_l already defined in LIBCMT.lib(isctype.obj)
1>LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype already defined in LIBCMT.lib(isctype.obj)
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library

You seem to be linking projects built with different CRT library settings, one with Multi-Threaded, another one with Multi-Threaded Debug. Adjust the settings for all the projects to use the very same flavour of the library and the issue should go away!

You wouldn't normally try and pull in LIBCMTD in a release build, it's the debug version of LIBCMT.
It seems that your release build is trying to link to something that was built debug. You probably have a broken dependency in your build, (or you missed rebuilding something to release by hand if your project is normally built in pieces).
It would seem likely that it's the freeglut_static.lib that wasn't rebuilt for retail. If that isn't it then try deleting all of your build products (*.obj, *.lib, *.pch, *.pdb) of course being careful to not delete things that you don't produce - third party libs, etc. Then build just release.

To add to the other remarks: Don't use "Edit and Continue" /EDITANDCONTINUE in release builds. That's a useful feature while debugging, as it can reduce rebuild times. But it does so by packing your executable in a non-optimized form.
You get the warning because the /OPT:ICF option will fold identical function bodies. This means two functions share the same address. Obviously this means you cannot edit & replace only one of them.

Related

How do I use 2 libraries with same external symbols?

I have 2 libraries in my project - MySQL C++ Connector and OpenSSL library for sockets, and as I think MySQL library already has OpenSSL functions inside.
Errors I get
Errors I get (in text format):
1>libcrypto.lib(libcrypto-lib-x509_d2.obj) : error LNK2005: X509_STORE_load_locations already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_free already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_set1_cert already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_set1_issuer already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_set_time already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_Calc_A already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_Calc_server_key already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_Verify_A_mod_N already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_Verify_B_mod_N already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_check_known_gN_param already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_get_default_gN already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_INFO_free already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_INFO_get0_CERT already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_INFO_get0_NAME already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_INFO_get_type already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_close already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_eof already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_error already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_load already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_open already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
My project include directories:
\asio-1.24.0\include
\openssl\Lib\x64\Release\include
\MySQL\Connector C++ 8.0\include\jdbc
Linker input:
\openssl\Lib\x64\Release\lib\libcrypto.lib
\openssl\Lib\x64\Release\lib\libssl.lib
crypt32.lib
mysqlcppconn-static.lib
Static and shared libraries cannot be mixed like that.
mysqlcppconn-static is statically linked with libssl, and attempting to link, again, with libssl is not going to work.
mysqlcppconn-static is meant to be used with special-purpose applications that get statically linked only with mysql, and so they can be distributed without the mysql and openssl libraries.
Whenever multiple libraries are involved the only practical approach is to link only with shared libraries.

How to read sqlite data using C++.?

I want to read sqlite database file using c++ and VS2010 and i am writing below code.
sqlite3 *db;
int rc = sqlite3_open("test.db", &db);
I am getting this kind of error
lib(MSVCR100.dll) : error LNK2005: _strncmp already defined in LIBCMTD.lib(strncmp.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _realloc already defined in LIBCMTD.lib(dbgrealloc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memmove already defined in LIBCMTD.lib(memmove.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _atoi already defined in LIBCMTD.lib(atox.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 LIBCMTD.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 LIBCMTD.lib(typinfo.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>output\win32\Debug\SC.exe : fatal error LNK1169: one or more multiply defined symbols found
I did included sqlite3.lib in project and had given path ..
Within your project, you are trying to use both the DEBUG version and the RELEASE (NON-DEBUG) version of the C standard library.
This means that sqlite3.lib is using one kind of C standard library, and your project is using another. Your project, and the used libraries must match the Debug/Release choice, and the Static/Dynamic use of Standard Library choice.

fatal error LNK1169

The below error list pops up.
I am okay if this had happened on Release build.
It is quite surprising that it has happened in DEBUG build.
1>libcmtd.lib(dbgheap.obj) : error LNK2005: malloc already defined in libcmt.lib(malloc.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _heap_alloc already defined in libcmt.lib(malloc.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: calloc already defined in libcmt.lib(calloc.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: realloc already defined in libcmt.lib(realloc.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _recalloc already defined in libcmt.lib(realloc.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _expand already defined in libcmt.lib(expand.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: free already defined in libcmt.lib(free.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _msize already defined in libcmt.lib(msize.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _aligned_malloc already defined in libcmt.lib(align.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _aligned_realloc already defined in libcmt.lib(align.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _aligned_recalloc already defined in libcmt.lib(align.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _aligned_offset_malloc already defined in libcmt.lib(align.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _aligned_offset_realloc already defined in libcmt.lib(align.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _aligned_offset_recalloc already defined in libcmt.lib(align.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _aligned_free already defined in libcmt.lib(align.obj)
1>libcmtd.lib(dbgheap.obj) : error LNK2005: _aligned_msize already defined in libcmt.lib(align.obj)
1>libcmtd.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in libcmt.lib(dbghook.obj)
1>libcmtd.lib(isctype.obj) : error LNK2005: _isctype_l already defined in libcmt.lib(isctype.obj)
1>libcmtd.lib(isctype.obj) : error LNK2005: _isctype already defined in libcmt.lib(isctype.obj)
It looks like you're linking to the Debug runtime as well as the Release runtime - probably you have a Release build that links statically to a Debug lib or vice versa.
If your application use any LIBs or DLLs any of those are statically link with run-time assemblies. that's the reason for this linking error.
Run-time assemblies statically liking is not a recommended method
But if you need to get rid from this linking error here you go, right-click on project file in project explorer -> properties -> configuration properties -> linker -> Input -> Ignore Specific Library -> add libcmtd.lib

How can the Interactive Brokers API C++ test socket client be built with VS2010

Having followed the instructions given here http://www.interactivebrokers.com/php/apiUsersGuide/apiguide.htm#apiguide/c/using_the_c__testsocketclient_sample_program.htm
under Visual Studio Professional 2010, the c++ project always gives the following output:
1> Generating Code...
1>LIBCMT.lib(invarg.obj) : error LNK2005: __initp_misc_invarg already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __call_reportfault already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __get_invalid_parameter_handler already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: "void __cdecl _invoke_watson(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invoke_watson##YAXPBG00II#Z) already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: "void __cdecl _invalid_parameter(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invalid_parameter##YAXPBG00II#Z) already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: ___pInvalidArgHandler already defined in libcmtd.lib(invarg.obj)
1> Creating library C:\Syncing\VCPlusPlus\IBTestSocketClientVS2010\Debug\SampleSocketClient.lib and object C:\Syncing\VCPlusPlus\IBTestSocketClientVS2010\Debug\SampleSocketClient.exp
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\Syncing\VCPlusPlus\IBTestSocketClientVS2010\Debug\SampleSocketClient.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:01:30.63
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If anyone has had experience of this or understands how to fix this bug, it would be much appreciated!
I guess I found the answer for you. I followed the indication of the error LNK2005 description and it indicates that there is some double linking thing happening behind the scenes.
The only thing you need to do is change the properties of your project Configuration:
Properties->Linker->Input->Ignore Specific Default Libraries
Here, you should set up the library you wanna ignore which is libcmt.lib. After setting up, you should see the value of Ignore Specific Default Libraries is:
libcmt.lib;%(IgnoreSpecificDefaultLibraries)
Then build, binggo~~~~ Please try it out.
Looks like you need to fix your lib references. By the looks of below error, your project is referencing both the release and debug versions, hence the linker is not sure where to look for specific symbols as it is defined in multiple places (both debug and release):
BlockquoteLIBCMT.lib(invarg.obj) : error LNK2005: ___pInvalidArgHandler already defined in libcmtd.lib(invarg.obj)
In case you are not referencing any libs and the IB dll is doing it behind the scenes, you may want to explore the NODEFAULTLIB option through your VS.
The problem is that the PosixSocketClient code assumes that when compiled with a Microsoft compiler, Microsoft Foundation Library (MFC) is going to be used. Maybe it used to work like that in the past but I never got it working with VS2010. But I did get it working by removing dependency on/linking with MFC.
Unfortunately, code in Shared subfolder automatically assumes MFC if _MSC_VER is defined.
(_MSC_VER gives the version of Microsoft C++ compiler).
It cannot be simply undef-ined because some standard Windows headers use it.
This is clearly a bug as the presence of MFC is signalled by _MFC_VER, not _MSC_VER.
Therefore I had to change
#ifdef _MSC_VER
everywhere in EClientSocketBaseImpl.h into
#ifdef _MFC_VER
Also, in file _StdAfx.h, #include <afxwin.h> should be wrapped additionally in a conditional compilation directive:
#ifdef _MFC_VER
#include <afxwin.h>
#endif

Problem statically linking MFC libraries

I have a Visual Studio 6 workspace I'm trying to convert to a Visual Studio 2008 solution. The output of said solution is a .dll. It has to be a .dll and it needs to statically link MFC as I can't redistribute MFC to existing customers.
The solution consists of three projects, say A, B, C. C is the Active Project, outputs the .dll and depends on B. B outputs a .lib and depends on A. A outputs a .lib.
In the General configuration properties I have A and B set to Static Library (.lib) and C set to Dynamic Library (.dll). All three projects are set to "Use MFC in a Static Library." Also, all three projects are set to "Multi-threaded" for Runtime Library and none of them have _AFXDLL defined.
Everything builds correctly up until the final linking stage where I see this:
1>nafxcw.lib(wincore.obj) : error LNK2005: _IsPlatformNT already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _InitMultipleMonitorStubs already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _xGetSystemMetrics#4 already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _xMonitorFromPoint#12 already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _xMonitorFromRect#8 already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _xMonitorFromWindow#8 already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _xGetMonitorInfo#8 already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _xEnumDisplayMonitors#16 already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _xEnumDisplayDevices#16 already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnGetSystemMetrics already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnMonitorFromWindow already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnMonitorFromRect already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnMonitorFromPoint already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnGetMonitorInfo already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnEnumDisplayMonitors already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnEnumDisplayDevices already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_fMultiMonInitDone already defined in A.lib(Globals.obj)
1>nafxcw.lib(wincore.obj) : error LNK2005: _g_fMultimonPlatformNT already defined in A.lib(Globals.obj)
1>nafxcw.lib(viewprnt.obj) : error LNK2005: "public: virtual int __thiscall CPrintingDialog::OnInitDialog(void)" (?OnInitDialog#CPrintingDialog##UAEHXZ) already defined in B.lib(ImagePropertiesDlg.obj)
1>nafxcw.lib(viewprnt.obj) : error LNK2005: "public: __thiscall CPrintingDialog::CPrintingDialog(class CWnd *)" (??0CPrintingDialog##QAE#PAVCWnd###Z) already defined in B.lib(ImagePropertiesDlg.obj)
1>nafxcw.lib(viewprnt.obj) : error LNK2005: "public: virtual void __thiscall CPrintingDialog::OnCancel(void)" (?OnCancel#CPrintingDialog##UAEXXZ) already defined in B.lib(ImagePropertiesDlg.obj)
I've Googled the problem to death and seen other people with a similarish issue, but can't seem to solve it. I tried adding nafxcw.lib to the Ignored libraries for C, but that turned this batch of linker errors into 1500+ unresolved symbol errors. I can get it to compile/link if I make it dynamically link MFC, but like I said, I need it to statically link. I feel like I'm missing something rather simple but can't seem to wrap my head around it. Any and all random thoughts and ideas will be greatly appreciated.
As is often the case, the solution turned out to be so mundane and obvious, I'm still kicking myself for banging my head on it for so long.
Basically, project A referenced above was not a project I directly pulled from the old VS6 workspace, but rather a project that had previously been converted by another team for use in another application. I assumed it was functionally equivalent to the original one, but that is very much not the case. These linking errors are actual, valid multiply defined linking errors. When I started digging in, I found that the first batch of errors was from including multimon.h in project A (something I don't even need, just removed it) and the second batch is from a class that is actually defined in both A and B.
Like I said, I'm still groaning over here, but at least I should be able to fix my problem now. Thanks for the help and always remember to NEVER assume ANYTHING.
When you tried ignoring the nafxcw library, did you add it back in to try to force a link order as suggested by this KB article? While your problem isn't an exact fit it may be related. Perhaps things could be resolved by monkeying with the link order.