jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
5.06k stars 1.82k forks source link

in cmakelist ,find_package(Yaml-cpp),target_link_libraries(camyaml ${Yaml-cpp_LIBS})erro #496

Open ghost opened 7 years ago

ghost commented 7 years ago

ubuntu: after: cd build cmake .. make sudo make install then in cmakelist i write: find_package(Yaml-cpp) target_link_libraries(camyaml ${Yaml-cpp_LIBS}) when i cmake .. my project ,show erro:

By not providing "FindYaml-cpp.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Yaml-cpp", but CMake did not find one.

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

Yaml-cppConfig.cmake
yaml-cpp-config.cmake

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

how can i solve it?

keith-bennett-gbg commented 7 years ago

~The package name passed to FIND_PACKAGE cmake command is case sensitive. You're trying to find package Yaml-cpp, but it is being exported as yaml-cpp.~

Edit: actually this comment about case sensitivity is incorrect.

keith-bennett-gbg commented 7 years ago

You'll need to figure out why your cmake isn't finding your installed package. On my machine, I'm using Ubuntu 16.04 LTS with cmake built (tagged 3.8.0) and installed to /usr/local/bin/cmake.

When you do sudo cmake install, what is the output? On my machine, it installs (among other things) /usr/local/lib/cmake/yaml-cpp/yaml-cpp-config.cmake. Cmake should look at /usr/local/lib/cmake by default and find that. cmake install should also produce an install_manifest.txt file in the build directory which will tell you what file/directory locations it has touched.

You might also try using FIND_PACKAGE's HINTS or PATHS parameters.

As a stopgap measure (ugly hack), you can change the installation path by doing

cd path/to/yaml-cpp/build
cmake -DCMAKE_INSTALL_PREFIX=~/local/ ../
make
make install

Then in your project, you can do:

cmake -DYaml-cpp_DIR=~/local/lib/cmake/yaml-cpp ../

However, that is obviously not ideal, particularly if you need to install your application for others to use -- now the library is installed into your ${HOME}/local where other users wouldn't be able to use it. On the other hand, if you use cmake's CPack features, you can get around that by installing yaml-cpp with your project.

liaoqinghai commented 6 years ago

My machine is Ubuntu 16.04LTS and install the yaml-cpp by

sudo apt install libyaml-cpp0.5v5 libyaml-cpp-dev

and I can find the cmake file at /usr/lib/x86_64-linux-gnu/cmake/yaml-cpp and use it in CMakeLists.txt like

find_package(  yaml-cpp REQUIRED )
# ${YAML_CPP_INCLUDE_DIR}
# ${YAML_CPP_LIBRARIES}

But got another two problems:

  1. We find lib by yam-cpp but cmake variables prefix is YAML_CPP
  2. The inlcude dir of most lib I used is xxx__INCLUDE_DIRS

They are not big problem and not affect the lib, but there is no doc about this and we have read the source code of *.cmake files which is not good.