You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用conda版yaml-cpp编译链接程序失败问题求助

CentOS7下devtoolset-10搭配conda安装的yaml-cpp编译链接失败

环境配置步骤

  • 激活devtoolset-10环境:
    scl enable devtoolset-10 bash
    
  • 创建并激活包含yaml-cpp的conda环境:
    conda create -n test-yaml-cpp python=3.10 yaml-cpp=0.7.0
    conda activate test-yaml-cpp
    

测试代码(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;
}

编译尝试与报错

执行编译命令:

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

补充说明

  • 未额外设置环境变量;使用自行编译安装的yaml-cpp 0.7.0可正常编译:
    g++ -o test -I/opt/3rd-party/yaml-cpp/include -L/opt/3rd-party/yaml-cpp/lib64 test.cpp -lyaml-cpp
    
  • 编辑1:调整g++参数顺序后问题仍未解决。
  • 编辑2:通过conda的CentOS7镜像复现问题,步骤如下:
    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
    
    报错信息与之前一致:
    /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
    

内容的提问来源于stack exchange,提问作者dagnic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 00:35:37