我如何编译一个应用程序对使用libc ++在xcode / clang / macos中编译的静态库? [英] How I do compile a application against a static library compiled with libc++ in xcode/clang/macos?

查看:914
本文介绍了我如何编译一个应用程序对使用libc ++在xcode / clang / macos中编译的静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译测试控制台应用程序来测试同一工作空间上的静态库的某些功能时,我在二进制链接阶段遇到问题,它只发生在我选择使用libc ++标准库。 / p>

缺少的符号错误如下:

  x86_64:
std :: __ 1 :: basic_string< char,std :: __ 1 :: char_traits< char>,std :: __ 1 :: allocator< char>> :: empty :
libtorrent :: torrent :: replace_trackers(std :: __ 1 :: vector< libtorrent :: announce_entry,std :: __ 1 :: allocator< libtorrent :: announce_entry> const&)in libLibOFFTorrent-xcode.a (torrent.o)
ld:没有为架构找到符号x86_64
clang:error:linker命令失败,退出代码1(使用-v查看调用)



当我在两个目标中选择stdlibc ++时,一切编译正常,运行正常。





my问题是:


  1. 在静态库上使用libc ++有一些限制吗?


  2. 如何配置项目以使用静态
    库来使用libc ++?
  3. 工具在静态lib?上找不到标准c ++
    库的符号(任何其他依赖的库都是针对libc ++编译的)
  4. 如果我忘记了使用libc ++?

注意:


  1. 静态库依赖于libboost_system,我使用libc ++和libstdc ++编译了相同的结果

  2. 当我使用'bjam'工具运行测试运行OK,也许jam文件选择libstdc ++编译文件。

  3. 我知道更改标准库修复了链接问题,我只想知道为什么。

UPDATE :当我在静态lib项目中删除对string :: empty的引用时,项目依赖于编译libc ++ fine并运行,但它

UPDATE 2 :删除string :: empty引用在使用libstdc ++编译整个事物时不会产生任何影响运行良好。没有循环,这让我认为是一个错误或类似的东西。



UPDATE 3 :当它编译这是程序循环无限期:

解决方案

看起来你的依赖关系( libtorrent )是建立在 libstdc ++



检查命名空间: std :: __ 1 :: basic_string 。它有 __ 1 前缀,通常表示 libstdc ++ )。



我可能是错了,但我想你需要重建 libtorrent libc ++ 如果你绝对要使用这个一个。



请注意,使用 stdlibc ++ 很常见。


When I try to compile a test console application to test some functionality on a static library on the same workspace, i run into problems in the linking stage of the binary, it only happen when I choose to use libc++ standard library.

The missing symbols error is the follow :

    Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::empty() const", referenced from:
      libtorrent::torrent::replace_trackers(std::__1::vector<libtorrent::announce_entry, std::__1::allocator<libtorrent::announce_entry> > const&) in libLibOFFTorrent-xcode.a(torrent.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

When I choose stdlibc++ in both targets everything compiles ok and it runs OK.

my questions are :

  1. there are some restriction on using libc++ on static libraries?
  2. its a bug in apple/clang++ linker tool?
  3. how can I configure the project to use libc++ with my static libraries?
  4. why the linker tool does not find the symbols of a standard c++ libraries on a static lib?, (any other lib that depends on is compiled against libc++)
  5. should I forget the idea on using libc++?

notes:

  1. the static library depends on libboost_system, witch i had compiled with libc++ and libstdc++ with the same results
  2. when i run the test with the 'bjam' tool it runs OK, maybe the jam files chooses libstdc++ to compile the files.
  3. I know that changing the standard library fix the linking problem , I only want to know why is that.

UPDATE: when I remove the reference to string::empty in the static lib project, the project that depends on compiles with libc++ fine and runs, but it gets in a infinite loop.

UPDATE 2: removing the string::empty references causes no effect when I compile the whole thing with libstdc++ it runs fine. no loops, this makes me think that is a bug or something like that.

UPDATE 3: when it compiles this is the place where the programs loops indefinitely :

解决方案

It seems that one of your dependencies (libtorrent) has been built against libstdc++.

Check the namespace : std::__1::basic_string. It has the __1 prefix, usually indicating libstdc++).

I may be wrong but I think you need to rebuild your libtorrent against libc++ if you absolutely want to use this one.

Note that it is pretty common to use the stdlibc++.

这篇关于我如何编译一个应用程序对使用libc ++在xcode / clang / macos中编译的静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆