需要在cmake debug build中使用release库

时间:2018-05-26 23:27:06

标签: c++ visual-studio debugging cmake static-libraries

我使用CMAKE生成了一个需要保持专有的版本库。我计划将头文件放入include目录,将库文件放入lib目录。

用于生成库的CMAKE行是:

add_library(Ethernet STATIC ${eth_srcs} $<TARGET_OBJECTS:EthernetBootloader>)

有单独的Visual Studio解决方案,用于生成库并运行使用该库的控制面板。在调试模式下运行控制面板仅适用于调试库。如果控制面板在调试模式下编译并运行,并且库是在发布模式下构建的,那么我会得到几个看起来像的错误:

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

我开始编写一个包含以下内容的“ethernet-config.cmake”文件:

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)

和CMakeLists.txt看起来像:

set(Ethernet_DIR "C:/MotorController/public")
find_package(Ethernet REQUIRED)
include_directories(${ETHERNET_INCLUDE_DIR})
target_link_libraries(ControlPanel ${ETHERNET_LIBRARIES})

如何在Visual Studio 2015 Windows 7 64位调试应用程序中使用发布库?我想我需要调整我的CMakeLists.txt用于调试应用程序,但还没有想出来。

0 个答案:

没有答案
相关问题