我編寫一個簡單的測試程序,它利用了lapack
,但是我有3個版本安裝LAPACK庫(一個來自蘋果/usr/lib
,一個從MacPorts的在/opt/local/lib
和一個我在/usr/local/lib
安裝過)。鏈接到一個特定圖書館
我有以下的CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.0)
project(delme)
include_directories(../../include /usr/local/include/boost-numeric-bindings)
find_library(lapack_LIBRARY NAMES lapack liblapack HINTS /usr/local/lib)
find_library(atlas_LIBRARY NAMES atlas libatlas HINTS /usr/local/lib)
find_library(cblas_LIBRARY NAMES cblas libcblas HINTS /usr/local/lib)
add_executable(delme test.cpp main.cpp)
target_link_libraries(delme lapack atlas cblas)
install(TARGETS delme RUNTIME DESTINATION bin)
調用cmake . && make VERBOSE=1
後,我得到的輸出結尾:
Linking CXX executable delme
/opt/local/bin/cmake -E cmake_link_script CMakeFiles/delme.dir/link.txt --verbose=1
/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/delme.dir/test.cpp.o CMakeFiles/delme.dir/main.cpp.o -o delme -llapack -latlas -lcblas
Undefined symbols for architecture x86_64:
"_clapack_dgetrf", referenced from:
boost::numeric::bindings::atlas::detail::getrf(CBLAS_ORDER, int, int, double*, int, int*) in main.cpp.o
"_clapack_dgetri", referenced from:
boost::numeric::bindings::atlas::detail::getri(CBLAS_ORDER, int, double*, int, int const*) in main.cpp.o
"_clapack_dpotrf", referenced from:
boost::numeric::bindings::atlas::detail::potrf(CBLAS_ORDER, CBLAS_UPLO, int, double*, int) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
這些符號都在/usr/local/lib
和MacPorts的版本,但不是蘋果的版本,這似乎是它連接的一個版本。 如果我手動將-L/usr/local/lib
添加到CMake生成的文件CMakeFiles/delme.dir/link.txt
,那麼它編譯得很好。
我的問題是,我如何指示cmake將-L/usr/local/lib
包含在鏈接命令(或其他備選)中,以便它使用/usr/local/lib
中的版本?
在三個庫路徑中,它們中的任何一個是否在PATH環境變量中?他們的順序是什麼? – jmstoker 2014-10-02 20:30:44
不,沒有任何庫路徑在我的$ PATH環境變量中。 – 2014-10-03 07:17:43