【发布时间】:2013-03-12 06:18:23
【问题描述】:
我想使用 CMake 将我的项目链接到我的共享库。该库仅在少数项目之间共享并且相当小,所以我真的很想在链接之前构建它。每次都构建它似乎比维护一个最新的预编译版本更好,因为我要与项目一起更改它。它是独立的,因为它包含我在下一个项目中几乎肯定会需要的东西。
如何配置 CMake 来做到这一点?
我当前的相关项目的 CMakeLists.txt 如下所示:
find_package( Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(${BaumWelch_SOURCE_DIR}/../../grzesLib/src
${BaumWelch_SOURCE_DIR}/src
${Boost_INCLUDE_DIRS})
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-g -std=c++11 -Wall -Werror -Wextra -pedantic -Wuninitialized)
endif()
# Create the unit tests executable
add_executable(
baumwelchtests stateindextest.cpp baumiterationtest.cpp baumwelchtest.cpp sampleparameters.cpp sdetest.cpp
# Key includes for setting up Boost.Test
testrunner.cpp
# Just for handy reference
exampletests.cpp
)
# Link the libraries
target_link_libraries( baumwelchtests ${Boost_LIBRARIES} baumwelchlib grzeslib)
但显然编译失败:
/usr/bin/ld: cannot find -lgrzeslib
【问题讨论】:
-
将.a添加到libname是否有效?
-
@drescherjm,这个库可能在那时甚至没有编译,而且我没有指定二进制文件的任何位置,所以我确信将 .a 添加到 libname 将无济于事。
标签: c++ dependencies cmake