3

I am trying to compile a piece of C++ code on a server with CentOS. I need to include a library (NLopt) that is installed as a module at the location "/services/tools". I have tried "module load NLopt", but CMake does still not find the library.

What do I need to do to make CMake find the package?

Christian Ravn
  • 187
  • 1
  • 2
  • 14
  • 1
    Looks like you want similar things as in [this question](http://stackoverflow.com/q/34795816/3440745). And its answer should work for you too: setting `CMAKE_PREFIX_PATH` CMake variable to `/services/tools`. – Tsyvarev Mar 14 '16 at 19:09

2 Answers2

2

"By default, [it] installs the NLopt static library (libnlopt.a) in /usr/local/lib and the NLopt header file (nlopt.h) in /usr/local/include, as well manual pages and a few other files."

So, you can include the header as

include_directories("/usr/local/include")

and link the library as

target_link_libraries(project "/usr/local/lib/lbnlopt.a")

Ideally you could try to find a CMake find module for the library.

Ramon
  • 1,169
  • 11
  • 25
  • Thank you for the answer. The problem is that it is not installed in the default directory, but in /services/tools/. I do have a CMake find module for it, but it is unable to locate the library because of the directory it is installed. I could just refer to the path as you suggest, but I would prefer a cleaner way to handle the path if possible. Most of my confusion here probably is probably because I don't know whether this is and OS or CMake issue. – Christian Ravn Mar 14 '16 at 18:53
  • My apologies, I overlooked the fact that you stated it's in a different location. Does your find module check under "/services/tools"? It's not a standard location, so it is unlikely that it does. If indeed it doesn't, you could modify it to look for it in that location. However, that is less clean than just referring to the path in your CMakeLists. – Ramon Mar 14 '16 at 19:03
  • Find modules generally don't do an extensive search of your system, they just look in a few locations where libraries are expected to be, like `/usr/local/include`, `/usr/local/lib`, `usr/include`, `usr/lib`, etc. – Ramon Mar 14 '16 at 19:05
0

Assuming your libraries are in /service/tools/lib and the headers in /service/tools/include, you can also set CMAKE_PREFIX_PATH, like this:

list(APPEND CMAKE_PREFIX_PATH /service/tools)
Dimitri Merejkowsky
  • 1,001
  • 10
  • 12