问题
How do I tell the compiler, in CMake where a specific library is?
For example, using terminal the following works:
g++ main.cpp hmm.cpp -I /usr/include/atlas -L /usr/lib64/atlas/ -llapack -lblas
But, how do I include the following inside of my CMake file?
I am using the ROS operating system and currently have:
rosbuild_add_executable(build src/hmm.cpp)
回答1:
The traditional way of finding libraries is to use find_package. It is often necessary to provide a FindLIBNAME. For LAPACK, CMake already ships with one. For atlas you will have to provide one yourself.
You use them like this:
find_package(LAPACK)
if(LAPACK_FOUND)
target_compile_options(my_exe_target ${LAPACK_LINKER_FLAGS})
target_link_library(my_exe_target ${LAPACK_LIBRARIES})
else()
# panick
endif()
Usually find_package would also export the include directory, but this doesn't seem to be the case for FindLAPACK
, which is really strange. You might want to provide a version that doesn't suck, like this one.
来源:https://stackoverflow.com/questions/21614824/cmake-link-atlas-and-llapack