1

自从最近更新 Mavericks 以来,我在链接库 json_spirit 时遇到了问题。

我安装了新的命令行工具,但我使用的是通过 macports 安装的 gcc47。Json Spirit (v4.06) 已用相同的 gcc 编译(更新后)。

gcc (MacPorts gcc47 4.7.3_3) 4.7.3

我将其归结为以下示例:

测试.cpp

#include <iostream>
#include "json_spirit_reader_template.h"
#include "json_spirit_writer_template.h"
#include "json_spirit_writer.h"

int main(int argc, char **argv) {
    json_spirit::mValue a;
    std::string s("[]");
    json_spirit::read_string(s, a);
    std::cout << json_spirit::write_formatted(a) << std::endl;
    return 0;
}

我用以下内容编译:

g++ -I/usr/local/include test.cpp -o test -L/usr/local/lib -ljson_spirit 

它给出了这个错误:

Undefined symbols for architecture x86_64:
  "json_spirit::write_formatted(json_spirit::Value_impl<json_spirit::Config_map<std::basic_strin    g<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
      _main in ccwUclng.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

最后,使用 "nm -g /usr/local/lib/libjson_spirit.a | grep write_formatted" :

nm: no name list
0000000000000150 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE
000000000003afa8 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE.eh
0000000000000120 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE
000000000003af80 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE.eh
0000000000000270 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE
000000000003b118 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE.eh
0000000000000240 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE
000000000003b0c8 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE.eh
0000000000000090 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE
000000000003aeb0 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE.eh
0000000000000060 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE
000000000003ae88 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE.eh
0000000000000210 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE
000000000003b0a0 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE.eh
00000000000001e0 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE
000000000003b078 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE.eh

我不知道如何读取 nm 输出,所以我可能遗漏了一些明显的东西。

我尝试一个一个地安装和卸载每个组件(boost ..),使用来自 macports 的 gcc 和/或默认值进行编译,即:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
4

1 回答 1

0

好吧,这是一个一半的答案,因为我从来没有真正解释到底发生了什么,但我修复了它,所以..

答案是从头开始重建boost,(也包括icu)使用新系统和到处相同的编译器,对我来说,它是安装了macports的gcc 4.7.3。

另外,我试图从 boost 1.53 升级到 boost 1.54,所以这可能是问题的一部分,但现在无论如何我又回到了 boost 1.53。

于 2013-10-28T12:46:15.083 回答