简体   繁体   中英

Adding an External Library to a cmake project

I'm a robotics' student from Instituto Superior Técnico and I'm having trouble using an external library in my project.

I use a Robotics simulator called Simox http://simox.sourceforge.net/ . This is a library that I have been working for a while. I have been using a cmake template file provided with the simulator (with few alterations) which lets me use Simox with my own code:

PROJECT ( myDemo )

FIND_PACKAGE(Simox REQUIRED)
IF(Simox_USE_COIN_VISUALIZATION)
  include_directories(${PROJECT_SOURCE_DIR}/include)

  FILE(GLOB SRCS ${PROJECT_SOURCE_DIR}/iCubSimulator.cpp ${PROJECT_SOURCE_DIR}/src/iCub.cpp ${PROJECT_SOURCE_DIR}/src/iCubHand.cpp ${PROJECT_SOURCE_DIR}/src/ApproachMovementSpace.cpp ${PROJECT_SOURCE_DIR}/src/OrientedBoundingBox.cpp ${PROJECT_SOURCE_DIR}/src/GraspOptimization.cpp ${PROJECT_SOURCE_DIR}/src/Window.cpp)
  FILE(GLOB INCS ${PROJECT_SOURCE_DIR}/include/iCub.h ${PROJECT_SOURCE_DIR}/include/iCubHand.h ${PROJECT_SOURCE_DIR}/include/ApproachMovementSpace.h ${PROJECT_SOURCE_DIR}/include/OrientedBoundingBox.h ${PROJECT_SOURCE_DIR}/include/Window.h)
  set(GUI_MOC_HDRS ${PROJECT_SOURCE_DIR}/include/GraspOptimization.h ${PROJECT_SOURCE_DIR}/include/Window.h)
  set(GUI_UIS ${PROJECT_SOURCE_DIR}/ui/iCubSimulator.ui)
  set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -lpthread")

  SimoxQtApplication(${PROJECT_NAME} "${SRCS}" "${INCS}" "${GUI_MOC_HDRS}" "${GUI_UIS}")
ENDIF()

Currently, I want to use an additional Bayesian Optimization Library called BayesOpt: http://rmcantin.bitbucket.org/html/ . And I don't know how to correctly modify my cmake file to include this library.

I tried to do this own my own, with some help from google, tutorials and other asked questions, but with no success.

I'm hoping someone can help me with this problem.

Thanks in advance!

To use an external library, you will need to:

  • Make header files from the library accessible:

     INCLUDE_DIRECTORIES( includePath )

includePath being your Bayesian Optimization Library include folder (where .h files are)

  • Link with the library. To do so, just add:

     TARGET_LINK_LIBRARIES(${PROJECT_NAME} mylib)

myLib being your Bayesian Optimization Library .lib file or .so file

Maybe you'll first have to compile the "Bayesian Optimization Library"

If the library is correctly installed in your environment, there could be an easier way to have it be found using CMake find_package command, but I'm not familiar with it, I prefer to handle things manually as proposed aboce.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM