Question

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)
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top