Undefined link to YAML :: LoadFile

I am trying to use the new version of libyaml-cpp and have problems with linkers ( undefined reference to 'YAML::LoadFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)').

I create the library as follows:

cmake -DBUILD_SHARED_LIBS=ON ..
make
sudo make install

Then I turn on yaml-cpp/yaml.hand call YAML::LoadFile( some_string );. My compilation line:

g++ -L/usr/local/lib -I/usr/local/include -lyaml-cpp -std=c++0x -o $@  $^

I tried to put the exact file .sowhere no luck. Using nm, I see a function LoadFilein a shared library. I can’t understand if I somehow use the wrong assembly line or something is wrong with the library.

+4
source share
4 answers

. , GCC. , , :

g++ -L/usr/local/lib -I/usr/local/include -std=c++0x -o $@  $^ -lyaml-cpp
+6

​​ ? , gcc .

0

. , :

OSX El Capitan XCode (7.3) CLang ( LLVM Apple 7.3.0 (clang-703.0.29) yaml-cpp 0.5.3

, :

  • FindYamlCpp.cmake . /usr/local/share/cmake/Modules
  • CMakeFiles.txt, Yaml-cpp

    # YAML with yaml-cpp
    SET(YAMLCPP_STATIC_LIBRARY TRUE)
    FIND_PACKAGE(YamlCpp)
    IF(YamlCpp_FOUND)
        MESSAGE("yaml-cpp Library FOUND: yaml-cpp related sources will be built.")
    ELSEIF(YamlCpp_FOUND)
        MESSAGE("yaml-cpp Library NOT FOUND!")
    ENDIF(YamlCpp_FOUND)
    
  • src/CmakeFiles.txt FindYamlCpp

        # Enable Yaml 
        IF(YAMLCPP_FOUND)
            ADD_EXECUTABLE(my_exec my_source.cpp)
        ENDIF(YAMLCPP_FOUND)
    
  • , , ccmake:

    • set CMAKE_MODULE_PATH to / usr / local / share / cmake / Modules
    • Set CMAKE_EXEC_LINKER_FLAGS to -lyaml-cpp
0
source

Support for the new yaml-cpp API.

find_package(PkgConfig)
pkg_check_modules(YAMLCPP REQUIRED yaml-cpp>=0.5)
include_directories(${YAMLCPP_INCLUDE_DIRS})

add_executable(name src/name.cpp)
target_link_libraries(name ${catkin_LIBRARIES}  ${YAMLCPP_LIBRARIES})
0
source

Source: https://habr.com/ru/post/1529733/


All Articles