我想使用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