【问题标题】:libconfig++ -stdlib=libc++ Undefined symbolslibconfig++ -stdlib=libc++ 未定义符号
【发布时间】:2013-01-19 16:10:14
【问题描述】:

试图获得一个非常简单的 libconfig++ 工作示例。但是,由于编译器选项“-stdlib=libc++”和“-std=c++11”,我遇到了以下链接错误。

环境

达尔文 iMac.local 12.2.0

达尔文内核版本 12.2.0

xnu-2050.18.24~1/RELEASE_X86_64 x86_64

来源

  Config cfg;

  cfg.readFile( "example.cfg" );

  string value = "";

  const string& key = "application.base";

  cfg.lookupValue( key, value );

构建

clang++ -o main main.cpp -lconfig++ -stdlib=libc++ -std=c++11

错误

Undefined symbols for architecture x86_64:   "libconfig::Config::lookupValue(char   const*, std::__1::basic_string<char, std::__1::char_traits<char>,   std::__1::allocator<char> >&) const", referenced from:  
      libconfig::Config::lookupValue(std::__1::basic_string<char,   std::__1::char_traits<char>, std::__1::allocator<char> > const&,   std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)   const in main-mFa01w.o ld: symbol(s) not found for architecture x86_64 clang:   error:   linker command failed with exit code 1 (use -v to see invocation)  

【问题讨论】:

    标签: c++ c++11 config libc++ clang++


    【解决方案1】:

    错误信息表明这个成员函数:

    libconfig::Config::lookupValue(const std::string& path, std::string& value) const;
    

    是用-stdlib=libc++ 编译的(可能是内联的,但我猜)。而它又会调用这个成员函数:

    libconfig::Config::lookupValue(char const* path, std::string& value) const
    

    但是后一个函数不是用-stdlib=libc++ 编译的。

    最可能的解决方法是使用 -stdlib=libc++ 重新编译 libconfig++。

    【讨论】:

    • 是的,我尝试了多种构建配置,但没有成功。所以我退缩了,跑到了SO。谢谢你的时间。
    • 尝试“nm -gm libconfig++.dylib |c++filt |grep lookupValue”。如果您看到 "__1" libconfig++.dylib 中包含 libc++ 符号。否则其中包含 libstdc++ 符号。
    猜你喜欢
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 2012-03-23
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    相关资源
    最近更新 更多