且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在iOS项目中混合使用stdc ++和libc ++

更新时间:2023-08-24 17:10:52

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