我想使用CMake将我的项目链接到我的共享库。图书馆只在少数几个项目之间共享,而且很小,所以我真的很想在链接之前构建它。每次构建它似乎都比维护最新的预编译版本更好,因为我会将其与项目一起更改。它是分开的,因为它包含了我在下一个项目中几乎可以肯定需要的东西。使用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 2013-03-22 12:01:24
@drescherjm,这个库在那个时候甚至没有被编译过,而且我也没有指定二进制文件的位置,所以我确定将.a添加到libname中将无济于事。 – Grzenio 2013-03-22 15:07:04