简体   繁体   English

使用不同的NDK编译的C / C ++代码是否向前/向后兼容?

[英]Fowards/backwards compatibility of C/C++ code compiled with different NDKs?

I'm starting my first piece of Android programming, porting some libraries written in C and C++ to Android. 我正在开始我的第一篇Android编程,将一些用C和C ++编写的库移植到Android。 I am not building an app, except for testing the libraries: the product is the libraries, which will be supplied to my customers. 除了测试库之外,我没有构建任何应用程序:产品就是库,将提供给我的客户。 The libraries are mathematical modelling, running on the device, and have no web or cloud interfaces: customers who want to run them in the cloud already do that, using the Linux or Windows builds. 这些库是数学建模的,可以在设备上运行,并且没有Web或云接口:想要在云中运行它们的客户已经使用Linux或Windows版本来做到这一点。

My initial customer is using NDK 14b. 我的最初客户正在使用NDK 14b。 I could use that, or I could use the latest NDK, 16b. 我可以使用它,也可以使用最新的NDK 16b。 If I compile C code with NDK 16b, a compatible instruction set and the same C++ run-time and target API version as my customer, will they be able to use static libraries that I've built in their NDK 14b app? 如果我使用NDK 16b,兼容的指令集以及与客户相同的C ++运行时和目标API版本来编译C代码,他们将能够使用我在其NDK 14b应用程序中内置的静态库吗?

The other way around is also interesting: if I use NDK 14b, and another customer comes along who uses NDK 16b, will static libraries I've built with 14b work in their 16b-built app? 另一种方法也很有趣:如果我使用NDK 14b,并且有另一个客户使用NDK 16b,我用14b构建的静态库是否可以在其16b构建的应用程序中使用? I'd be targeting an equal or earlier API to them, and the same instruction set and C++ run-time. 我将针对它们的一个相等或更早的API,以及相同的指令集和C ++运行时。

Addendum, much later: Building .so libraries turned out to be so easy that I've never used anything else. 附录,很久以后:构建.so库非常简单,以至于我再也没有使用过其他东西。

You kindof cannot target the same C++ runtime when you use a different NDK release. 当您使用不同的NDK版本时,您无法针对相同的C ++运行时。 The STL versions do not change too much, but there is no contract of their stability. STL版本的变化不大,但是没有稳定性的约定。

Except from this remark, static lib from NDK r16 will cooperate correctly with r14 and vice versa , but the bigger the gap is, the more glitches you should expect to handle. 除此之外,NDK r16的静态库将与r14正确配合, 反之亦然 ,但是差距越大,您应该期望处理的毛刺越多。

In general, NDK improvements involve bug fixing, so there is an incentive to use the latest release. 通常,NDK的改进涉及错误修复,因此有使用最新版本的动机。 But major progress is done in support of newer platform versions. 但是在支持较新的平台版本方面已经取得了重大进展。 This means that if your library will be linked into an app that targets Lollipop, the advantages of r16 will be less prominent. 这意味着,如果将您的库链接到针对Lollipop的应用程序,则r16的优势将不太明显。

Note that if you can ship your library as a linked shared library ( so ), your interdependency with the host app will be significantly less, and in my experience this improves stability and reduces clashes. 请注意,如果您可以将库作为链接的共享库发送( so ),则与主机应用程序的相互依赖性将大大降低,并且根据我的经验,这可以提高稳定性并减少冲突。 If that is relevant, this way is also more secure. 如果这是相关的,这种方式也更安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM