Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I've installed a library into my /usr/local directory. I would now like to include this directory into my CMakeLists.txt. How do I do this?

I have installed a library onto my system and I would now like to import this library to build with cmake in my CMakeLists.txt file but I’m not able to import it. I get errors that the library can’t be found when I run cmake ..

The library was installed to /usr/local and it is in a few sub folders here. I have them all listed below.

This is the part of my CMakeLists.txt which fails.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

find_package(MUJOCO REQUIRED)
link_libraries(MUJOCO::mujoco)

This is the error I get with this attempt to import the library in my CMakeLists.txt

CMake Error at CMakeLists.txt:65 (find_package):
  By not providing "FindMUJOCO.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "MUJOCO", but
  CMake did not find one.

  Could not find a package configuration file provided by "MUJOCO" with any
  of the following names:

    MUJOCOConfig.cmake
    mujoco-config.cmake

  Add the installation prefix of "MUJOCO" to CMAKE_PREFIX_PATH or set
  "MUJOCO_DIR" to a directory containing one of the above files.  If "MUJOCO"
  provides a separate development package or SDK, be sure it has been
  installed.

This is where the mujoco library was installed on my system, the library I want to include was installed.
I’m not sure it is write to hand code every one of these paths.

-- Install configuration: "Release"
-- Installing: /usr/local/bin/basic
-- Installing: /usr/local/bin/compile
-- Installing: /usr/local/bin/derivative
-- Installing: /usr/local/bin/record
-- Installing: /usr/local/bin/testspeed
-- Installing: /usr/local/bin/testxml
-- Installing: /usr/local/bin/simulate
-- Installing: /usr/local/lib/libmujoco.so.2.2.1
-- Installing: /usr/local/lib/libmujoco.so
-- Installing: /usr/local/include/mujoco/mjdata.h
-- Installing: /usr/local/include/mujoco/mjexport.h
-- Installing: /usr/local/include/mujoco/mjmodel.h
-- Installing: /usr/local/include/mujoco/mjrender.h
-- Installing: /usr/local/include/mujoco/mjtnum.h
-- Installing: /usr/local/include/mujoco/mjui.h
-- Installing: /usr/local/include/mujoco/mjvisualize.h
-- Installing: /usr/local/include/mujoco/mjxmacro.h
-- Installing: /usr/local/include/mujoco/mujoco.h
-- Installing: /usr/local/lib/cmake/mujoco/mujocoTargets.cmake
-- Installing: /usr/local/lib/cmake/mujoco/mujocoTargets-release.cmake
-- Installing: /usr/local/lib/cmake/mujoco/mujocoConfig.cmake
-- Installing: /usr/local/lib/cmake/mujoco/mujocoConfigVersion.cmake
-- Installing: /usr/local/share/mujoco/model
-- Installing: /usr/local/share/mujoco/model/hammock
-- Installing: /usr/local/share/mujoco/model/hammock/humanoid_body.xml
-- Installing: /usr/local/share/mujoco/model/hammock/hammock.xml
-- Installing: /usr/local/share/mujoco/model/tendon_arm
-- Installing: /usr/local/share/mujoco/model/tendon_arm/arm26.xml
-- Installing: /usr/local/share/mujoco/model/composite
-- Installing: /usr/local/share/mujoco/model/composite/scene.xml
-- Installing: /usr/local/share/mujoco/model/composite/cloth.xml
-- Installing: /usr/local/share/mujoco/model/composite/softbox.xml
-- Installing: /usr/local/share/mujoco/model/composite/asset
-- Installing: /usr/local/share/mujoco/model/composite/asset/sponge.png
-- Installing: /usr/local/share/mujoco/model/composite/asset/marble.png
-- Installing: /usr/local/share/mujoco/model/composite/asset/carpet.png
-- Installing: /usr/local/share/mujoco/model/composite/loop.xml
-- Installing: /usr/local/share/mujoco/model/composite/particle.xml
-- Installing: /usr/local/share/mujoco/model/composite/rope.xml
-- Installing: /usr/local/share/mujoco/model/composite/grid2pin.xml
-- Installing: /usr/local/share/mujoco/model/humanoid
-- Installing: /usr/local/share/mujoco/model/humanoid/22_humanoids.xml
-- Installing: /usr/local/share/mujoco/model/humanoid/humanoid.xml
-- Installing: /usr/local/share/mujoco/model/flag
-- Installing: /usr/local/share/mujoco/model/flag/flag.xml
-- Installing: /usr/local/share/mujoco/model/mug
-- Installing: /usr/local/share/mujoco/model/mug/mug.obj
-- Installing: /usr/local/share/mujoco/model/mug/mug.png
-- Installing: /usr/local/share/mujoco/model/mug/mug.xml
-- Installing: /usr/local/share/mujoco/model/slider_crank
-- Installing: /usr/local/share/mujoco/model/slider_crank/slider_crank.xml
-- Installing: /usr/local/share/mujoco/model/humanoid100
-- Installing: /usr/local/share/mujoco/model/humanoid100/humanoid100.xml
-- Installing: /usr/local/share/mujoco/model/humanoid100/humanoid_body.xml

>Solution :

The only cmake configuration files installed by the lib are

-- Installing: /usr/local/lib/cmake/mujoco/mujocoTargets.cmake
-- Installing: /usr/local/lib/cmake/mujoco/mujocoTargets-release.cmake
-- Installing: /usr/local/lib/cmake/mujoco/mujocoConfig.cmake
-- Installing: /usr/local/lib/cmake/mujoco/mujocoConfigVersion.cmake
find_package(<Package> ...)

in config mode checks for the files

<package>-config.cmake
<Package>Config.cmake

where <package> is the <Package> with the first character converted to lower case.

, see the find_package() documentation

You’ve used find_package(MUJOCO REQUIRED) in your cmake project, which means, cmake is looking for a file named mujoco-config.cmake or MUJOCOConfig.cmake, but not for mujocoConfig.cmake.

You need to use

find_package(mujoco REQUIRED)

instead.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading