问题描述
我很难配置iOS项目,该项目使用与gcc使用的旧libstdc ++链接的静态库。该库是32位和64位。
I am having a difficult time configuring an iOS project which uses a static library linked against the old libstdc++ that gcc used. That library is 32 and 64-bit.
有6个库(例如libssl.a)是32位的,必须更新。如果我从源代码编译这些库,它们将自动与libc ++链接,这将导致我的链接器抱怨。
There are 6 libraries (libssl.a for example) that are 32-bit and must be updated. If I compile those libraries from source, they will be automatically linked with libc++, which will result in my linker complaining.
因此,这是我的问题:
1)有没有办法让项目中的单个静态库使用libstdc ++,让其他人使用libc ++?
1) Is there any way to have a single static library inside the project use libstdc++, and have the others use libc++?
2)我怎么编译库从源(像libcrypto和libssh),并迫使他们使用旧的libstdc ++标准库?
2) How can I compile libraries from source (like libcrypto and libssh) and force them use the old libstdc++ standard library?
3)是否有任何其他的出路这个烂摊子?
3) Is there any other way out of this mess?
推荐答案
1)是的,你当然可以混合和匹配其C ++运行时将你的C ++代码使用,只要那些独立模块实际上并不在彼此之间传递对象。例如,如果您的应用程序中有两个模块只暴露C API但在内部使用C ++,那么每个模块都可以使用他们想要的任何C ++运行时。尝试在运行时之间共享对象时出现问题。
1) Yes, you can certainly mix and match which C++ runtimes your C++ code uses so long as those separate modules don't actually pass objects between each-other. For example, if you have two modules in your app which just expose C APIs but internally use C++, then each can use whichever C++ runtime they want. Problems occur when trying to share objects between the runtimes.
2)您可以使用'--stdlib = libstdc ++'或'--stdlib = libc ++'命令行参数编译和链接时指定要使用的C ++库。如果您的最终可执行文件需要对两种链接,您需要手动指定其他一个。(如:--stdlib =的libc ++ -lstdc ++)
2) You can use the '--stdlib=libstdc++' or '--stdlib=libc++' command line argument when compiling and linking to specify which C++ library to use. If your final executable needs to link against both, you'll need to manually specify the other one (eg: --stdlib=libc++ -lstdc++).
3)是的,但请注意libstdc ++在几年前已被弃用,甚至在watchOS和tvOS上都没有,所以最好的办法是将所有东西都放到libc ++上。
3) Yep, but note that libstdc++ was deprecated years ago and isn't even available on watchOS nor tvOS, so your best bet is to just get everything over to libc++.
这篇关于在iOS项目中混合使用stdc ++和libc ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!