I have generated a release library using CMAKE that needs to be kept proprietary. I plan to put header files into an include directory and library files into a lib directory.
The CMAKE line used to generate the library is:
add_library(Ethernet STATIC ${eth_srcs} $<TARGET_OBJECTS:EthernetBootloader>)
There are separate Visual Studio solutions for generating a library and running a control panel that uses the library. Running the Control Panel in debug mode only works with a debug library. If the Control Panel compiles and runs in debug mode and the library was built in release mode I get several errors that look like:
Ethernet.lib(ethernet.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
Ethernet.lib(ethernet.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.obj
I am beginning to write a "ethernet-config.cmake" file that contains:
set(ETHERNET_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include")
set(ETHERNET_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/Ethernet.lib")
string(STRIP "${ETHERNET_LIBRARIES}" ETHERNET_LIBRARIES)
and the CMakeLists.txt looks something like:
set(Ethernet_DIR "C:/MotorController/public")
find_package(Ethernet REQUIRED)
include_directories(${ETHERNET_INCLUDE_DIR})
target_link_libraries(ControlPanel ${ETHERNET_LIBRARIES})
How do I use a release library in a Visual Studio 2015 Windows 7 64-bit debug application? I think I need to adapt my CMakeLists.txt for the debug application but haven't figured it out.
Related
I have some problems with pjsua2.lib. I can't build this in QT. I added the following libraries:
INCLUDEPATH += "$$DIRECTX_PATH\Include"
INCLUDEPATH+="$$SIP_PATH\pjsip\include"
INCLUDEPATH+="$$SIP_PATH\pjlib\include"
INCLUDEPATH+="$$SIP_PATH\pjlib-util\include"
INCLUDEPATH+="$$SIP_PATH\pjnath\include"
INCLUDEPATH+="$$SIP_PATH\pjmedia\include"
INCLUDEPATH+="$$SIP_PATH\pjsip-apps\src\pjsua\pjsua_app.h"
INCLUDEPATH+="$$SIP_PATH\pjsip\src\pjsua-lib\pjsua_acc.c"
LIBS += "$$DIRECTX_PATH\Lib\x86\dsound.lib"
LIBS += "$$DIRECTX_PATH\Lib\x86\dxguid.lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\WS2_32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\Ole32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\WSock32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\IPHlpApi.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\NetAPI32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\AdvAPI32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\Gdi32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\User32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\odbccp32.lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\odbc32.lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\msvfw32.Lib"
LIBS+="$$WINDOWS_SDKS_PATH\Lib\Version.Lib"
LIBS+="$$SIP_PATH\lib\libpjproject-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsip-core-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsip-simple-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsip-ua-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsua2-lib-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjsip\lib\pjsua-lib-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjlib\lib\pjlib-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjlib-util\lib\pjlib-util-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjmedia\lib\pjmedia-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjnath\lib\pjnath-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libbaseclasses-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libg7221codec-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libgsmcodec-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libilbccodec-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libmilenage-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libportaudio-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libresample-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libspeex-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\third_party\lib\libsrtp-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjmedia\lib\pjmedia-audiodev-i386-Win32-vc8-Debug.lib"
LIBS+="$$SIP_PATH\pjmedia\lib\pjmedia-codec-i386-Win32-vc8-Debug.lib"
but these errors show up whenever I try to build the application:
pjsua2-lib-i386-Win32-vc8-Debug.lib(endpoint.obj):-1: error: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
I think the problem comes from the compiler, but in any way, I can't seem to solve it
This means that the library you are linking to has been build with a different version / variant of the CRT (C Runtime). You either need to rebuild the library or set the runtime library version + variant (release/debug, DLL/static) in your projects properties to the same settings as all the libraries you are linking to.
How can I force google test compile with /MT option?
I saw that google test tries to compile with MT(internal_utils.cmake line 33):
if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt)
string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
endif()
But it doesn't work (BUILD_SHARED_LIBS and gtest_force_shared_crt are disabled).
I gets error when my project compiles with MT:
gtest.lib(gtest-all.obj) : error LNK2038: mismatch detected for
"RuntimeLibrary": value "MD_DynamicRelease" does not match value
"MT_StaticRelease"
And more some LNK2005 and LNK4217.
If I try to compile my project without MT, all compiles ok.
How can I solve it? Thanks in advance!
That if is a test, implementing a switch allowing you to configure it before including googletest.
It's also mentioned in the manual:
Visual Studio Dynamic vs Static Runtimes
By default, new Visual Studio projects link the C runtimes dynamically
but GoogleTest links them statically. This will generate an error that
looks something like the following: gtest.lib(gtest-all.obj) : error
LNK2038: mismatch detected for 'RuntimeLibrary': value
'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
GoogleTest already has a CMake option for this: gtest_force_shared_crt
Enabling this option will make gtest link the runtimes dynamically
too, and match the project in which it is included.
So just set it in your project e.g. like this:
set(gtest_force_shared_crt on)
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main)
FetchContent_MakeAvailable(googletest)
enable_testing()
I'm working on a C++ application in Qt and got to a point where the compiler is at least able to open the included boost library files. Now I get:
LNK2038: mismatch detected for 'runtimelibrary' value
'MTd_StaticDebug' does not match 'MDd_DynamicDebug' in main.obj
So, I have skimmed other threats about this issue. The compiler version of Qt (msvc 2014) matches the one of the lib-files (i.e. libboost_filesystem-vc140-mt-sgd-1_61). This is my include for the debug-version (haven't tried release yet because that one has other issues to be solved later).
win32:CONFIG( debug, debug|release ) {
# debug
LIBS += -L$$PWD/boost/bin.v2/libs/filesystem/build/msvc-14.0/debug/address-model-64/link-static/runtime-link-static/threading-multi/ -llibboost_filesystem-vc140-mt-sgd-1_61
LIBS += -L$$PWD/boost/bin.v2/libs/filesystem/build/msvc-14.0/debug/address-model-64/link-static/threading-multi/ -llibboost_filesystem-vc140-mt-gd-1_61
LIBS += -L$$PWD/boost/bin.v2/libs/system/build/msvc-14.0/debug/address-model-64/link-static/threading-multi/ -llibboost_system-vc140-mt-gd-1_61
}
Now, it seems that there might be something wrong with the runtime settings (/MD, /MT) but - tbh I have no idea how to check that or fix it.
I have a C library project for UWP. There are some C files which are calling C++ WINRT functions defined in CPP file.It is compiling successfully and generating a library file(LIB). I am compiling in Visual Studio 2015 with update 1 and target platform is 10.0.10240.0
But, I want to generate DLL instead of LIB file. Here's the changes I did to change the project so that it generates DLL instead of LIB.
Try1:
So, In the startup project, In Configuration Properties => General I change Configuration from Static Library to Dynamic Library.
And in all the project, I changed from Multi-threaded Debug(/MTd) to Multi-threaded Debug DLL(/MDd).
Try2:
Created a new project Windows Universal Project and added the all the files from the project creating LIB to this project. Still, I am getting the below errors.
Now, I am getting the errors
vccorlibd.lib(init.obj) : error LNK2038: mismatch detected for 'vccorlib_lib_should_be_specified_before_msvcrt_lib_to_linker': value '1' doesn't match value '0' in msvcrtd.lib(app_appinit.obj)
vccorlibd.lib(init.obj) : error LNK2005: __crtWinrtInitType already defined in msvcrtd.lib(app_appinit.obj)
msvcrtd.lib(initializers.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
Any Suggestions how to resolve this.
I had the same Issue and fixed it using the linker flags:
/nodefaultlib:vccorlib /nodefaultlib:msvcrt vccorlib.lib msvcrt.lib
for debug builds you can use:
/nodefaultlib:vccorlibd /nodefaultlib:msvcrtd vccorlibd.lib msvcrtd.lib
The standard /nodefaultlib did not work for me.
The following linker flags (for debug) did the trick in my case:
/defaultlib:'vccorlibd.lib' /defaultlib:'msvcrtd.lib'
I'm trying to link Boost filesystem into my VS project. I built the boost libraries and when I include filesystem.hpp in my project I'm getting the following error:
Error 1 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in App.obj E:\SourceControl\zombiegame\ZombieGame\Projects\Windows\libboost_filesystem-vc120-mt-1_58.lib(operations.obj) ZombieGame
This is talking about the boost libraries having MD_DynamicRelease while my app has MT_StaticRelease. So I thought this was boost automatically linking for me since it's showing that it's using libboost_filesyste-vs12-mt-1_58.lib, but I think that's the shared version and I want to use the static version. So at the top before I include filesystem.hpp I added:
#define BOOST_FILESYSTEM_NO_LIB
To stop boost from automatically adding the shared lib and then I added the static lib to the linker but it still acts like it's using the shared lib. What am I missing here?