Mixing stdc++ and libc++ in an iOS project

纵饮孤独 提交于 2020-01-11 09:32:08

问题


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.

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.

Therefore, here are my questions:

1) Is there any way to have a single static library inside the project use libstdc++, and have the others use libc++?

2) How can I compile libraries from source (like libcrypto and libssh) and force them use the old libstdc++ standard library?

3) Is there any other way out of this mess?


回答1:


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) 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) 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++.




回答2:


As long as you don't mix objects (like passing a string from one library into a function that expects a different kind of string), you can do it by including both libraries when you build the top-level app.

In my case, it worked by setting the standard C++ lib to the GNU version and then adding libc++ as I would any other system library.



来源:https://stackoverflow.com/questions/32794607/mixing-stdc-and-libc-in-an-ios-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!