xcode 将 iOS 应用程序链接到 libstdc++ 和 libc++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15615364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Link iOS app against both libstdc++ and libc++
提问by AndiDog
Use case: I want to use a 3rd party static library that uses libstdc++ (cannot be changed), so I have to link my app against libstdc++. Now if I want to use C++11 features in my own code, I'd have to select libc++ in Xcode and additionally link against libstdc++ to satisfy the static library.
用例:我想使用使用 libstdc++(无法更改)的 3rd 方静态库,所以我必须将我的应用程序链接到 libstdc++。现在,如果我想在我自己的代码中使用 C++11 功能,我必须在 Xcode 中选择 libc++ 并另外链接 libstdc++ 以满足静态库。
My problem is that even though I selected libc++ in "Build settings" and added "-lstdc++" to "Other linker flags" (also tried via "Build phases > Link Binary With Libraries"), I'm getting linker errors for the latter, that is for libstdc++ functions/classes referenced by the 3rd party lib.
我的问题是,即使我在“构建设置”中选择了 libc++ 并将“-lstdc++”添加到“其他链接器标志”(也通过“构建阶段>链接二进制与库”进行了尝试),我收到了后者的链接器错误,即用于第 3 方库引用的 libstdc++ 函数/类。
How can I configure the project to link against both C++ standard libraries? It should theoretically be possible since libc++ will be in its own inline namespace std::__1
.
如何配置项目以链接两个 C++ 标准库?理论上应该是可能的,因为 libc++ 将在它自己的内联命名空间中std::__1
。
回答by SonicBison
I just ran into this , and my solution was that instead of adding -lstdc++
on the other flags, that you put /usr/lib/libstdc++.dylib
.
我刚刚遇到了这个,我的解决方案是,不要添加-lstdc++
其他标志,而是将/usr/lib/libstdc++.dylib
.
My hunch is that when xcode/clang has -std=c++
set, the older .dylib needs to be explicitly loaded.
我的预感是,当-std=c++
设置了xcode/clang 时,需要显式加载旧的 .dylib。