Ask Your Question

Revision history [back]

target_link_libraries(demo "/usr/lib/x86_64-linux-gnu/libnlopt.so"). That's a bit hacky... you'd be better off writing a FindNLOPT.cmake file. This might also require writing a NLOPTConfig.cmake file.

On my system, the target_link_libraries(demo "/usr/lib/x86_64-linux-gnu/libnlopt.so")nlopt version from apt-get has its headers and libs automatically installed to directories where CMake can find them. Therefore I can get away without using find_package at all and instead directly use target_link_libraries. That's a bit hacky... This isn't very portable, but it will likely solve your issue. In general, you'd likely be better off writing a FindNLOPT.cmake file. This FindNLOPT.cmake file, but this might also require writing a NLOPTConfig.cmake file.NLOPTConfig.cmake file (I'm no expert on writing those files, but it seems complicated to get versions that work well on all systems). The following CMakeLists.txt file builds a simple nlopt demo for me.

cmake_minimum_required (VERSION 2.6)

project(nlopt_test)

add_executable(demo example.cpp)
target_link_libraries(demo nlopt)

Perhaps that will help you sort out your errors.