I am working on CentOS7 with devtoolset-10 activated:
scl enable devtoolset-10 bash
Also working in a newly created conda environment
conda create -n test-yaml-cpp python=3.10 yaml-cpp=0.7.0
conda activate test-yaml-cpp
I am trying to compile a very simple program using yaml-cpp called test.cpp
#include <yaml-cpp/yaml.h>
#include <iostream>
int main (void){
YAML::Emitter out;
out << "Hello, World!";
std::cout << "Here's the output YAML:\n" << out.c_str();
return 0;
}
but linking fails, I don't understand why:
g++ -o test -I/local/home/dagnic/anaconda3/envs/test-yaml-cpp/include -L/local/home/dagnic/anaconda3/envs/test-yaml-cpp/lib test.cpp -lyaml-cpp
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /tmp/cc9sE2ck.o: in function `YAML::operator<<(YAML::Emitter&, char const*)':
test.cpp:(.text._ZN4YAMLlsERNS_7EmitterEPKc[_ZN4YAMLlsERNS_7EmitterEPKc]+0x43): undefined reference to `YAML::Emitter::Write(std::string const&)'
collect2: error: ld returned 1 exit status
I added nothing more in the environment variables.
I tried with a self-compiled and installed version of yaml-cpp 0.7.0 and I have no linking problem
g++ -o test -I/opt/3rd-party/yaml-cpp/include -L/opt/3rd-party/yaml-cpp/lib64 test.cpp -lyaml-cpp
EDIT 1: I fix the arguments order when calling g++ but it did not help.
EDIT 2: step to reproduce using a docker image from conda
docker run -i -t conda/miniconda3-centos7 /bin/bash
conda install -c conda-forge yaml-cpp
yum update -y
yum install -y centos-release-scl-rh
yum install -y devtoolset-10
export PATH=/opt/rh/devtoolset-10/root/bin:$PATH
# or scl enable devtoolset-10 bash
g++ -o test -I/usr/local/include -L/usr/local/lib test.cpp -lyaml-cpp
gives
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /tmp/cc22r2Wj.o: in function `YAML::operator<<(YAML::Emitter&, char const*)':
test.cpp:(.text._ZN4YAMLlsERNS_7EmitterEPKc[_ZN4YAMLlsERNS_7EmitterEPKc]+0x43):undefined reference to `YAML::Emitter::Write(std::string const&)'
collect2: error: ld returned 1 exit status