jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.92k stars 1.78k forks source link

Linking issue #1149

Closed gvbarroso closed 1 year ago

gvbarroso commented 1 year ago

Hi. I am trying to incorporate yaml-cpp to my project. I have a "Demes" class where I need to parse a YAML file.

This is the relevant method in Demes.cpp:

include "Demes.hpp"

void Demes::parse(const std::string& fileName) { // testing YAML::Node test = YAML::LoadFile(fileName);

}

where Demes.h includes the yaml-cpp files and declares the 'parse' method. When I try to build, I get:

[ 13%] Linking CXX executable momentspp /usr/bin/ld: CMakeFiles/momentspp.dir/Demes.cpp.o: in function Demes::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': Demes.cpp:(.text+0x1d): undefined reference toYAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' collect2: error: ld returned 1 exit status make[2]: [src/CMakeFiles/momentspp.dir/build.make:277: src/momentspp] Error 1 make[1]: [CMakeFiles/Makefile2:127: src/CMakeFiles/momentspp.dir/all] Error 2 make: *** [Makefile:156: all] Error 2

I am using Cmake to build my project, but I am still fairly unfamiliar with it. The start of my CMakeLists.txt file is:

cmake_minimum_required (VERSION 3.5.0) project (momentspp CXX)

SET(CMAKE_CXX_FLAGS "-std=c++20 -Weffc++ -Wshadow -Wall -Wextra -ffast-math -O3 -march=native")

And the part of my CMakeLists.txt file where I look for yaml-cpp is:

FIND_PACKAGE(yaml-cpp REQUIRED) IF(yaml-cpp_FOUND) INCLUDE_DIRECTORIES(${yaml-cpp_INCLUDE_DIRS}) SET(LIBS ${LIBS} ${yaml-cpp_LIBRARIES}) MESSAGE("-- yaml-cpp libraries found here:") MESSAGE(" includes: ${yaml-cpp_INCLUDE_DIRS}") ENDIF()

and this seems to be working, as far as I can tell.

How can I fix the linking issue? Thank you, Gustavo

jbeder commented 1 year ago

I think you’ll be better answers in Stack Overflow.

On Mon, Oct 31, 2022 at 4:08 PM Gustavo Valadares Barroso < @.***> wrote:

Hi. I am trying to incorporate yaml-cpp to my project. I have a "Demes" class where I need to parse a YAML file.

This is the relevant method in Demes.cpp:

include "Demes.hpp"

void Demes::parse(const std::string& fileName) { // testing YAML::Node test = YAML::LoadFile(fileName);

}

where Demes.h includes the yaml-cpp files and declares the 'parse' method. When I try to build, I get:

[ 13%] Linking CXX executable momentspp /usr/bin/ld: CMakeFiles/momentspp.dir/Demes.cpp.o: in function Demes::parse(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&)': Demes.cpp:(.text+0x1d): undefined reference to YAML::LoadFile(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&)' collect2: error: ld returned 1 exit status make[2]: [src/CMakeFiles/momentspp.dir/build.make:277: src/momentspp] Error 1 make[1]: [CMakeFiles/Makefile2:127: src/CMakeFiles/momentspp.dir/all] Error 2 make: *** [Makefile:156: all] Error 2

I am using Cmake to build my project, but I am still fairly unfamiliar with it. The start of my CMakeLists.txt file is:

cmake_minimum_required (VERSION 3.5.0) project (momentspp CXX)

SET(CMAKE_CXX_FLAGS "-std=c++20 -Weffc++ -Wshadow -Wall -Wextra -ffast-math -O3 -march=native")

And the part of my CMakeLists.txt file where I look for yaml-cpp is:

FIND_PACKAGE(yaml-cpp REQUIRED) IF(yaml-cpp_FOUND) INCLUDE_DIRECTORIES(${yaml-cpp_INCLUDE_DIRS}) SET(LIBS ${LIBS} ${yaml-cpp_LIBRARIES}) MESSAGE("-- yaml-cpp libraries found here:") MESSAGE(" includes: ${yaml-cpp_INCLUDE_DIRS}") ENDIF()

and this seems to be working, as far as I can tell.

How can I fix the linking issue? Thank you, Gustavo

— Reply to this email directly, view it on GitHub https://github.com/jbeder/yaml-cpp/issues/1149, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAICUBRL7GLDGG3KFNHCEPDWGAYMVANCNFSM6AAAAAARTPBVU4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>