简体   繁体   English

如何编写跨平台的C库并将其与iOS应用链接?

[英]How to write cross-platform C library and link it with iOS app?

I need a lib to do some kind of caching. 我需要一个lib来做某种缓存。 It must be cross-platform for reuse on Linux/Windows/iOS. 它必须是跨平台的,才能在Linux / Windows / iOS上重用。 How do I do that? 我怎么做?

If you really want to do this, you need to put platform specific code inside #ifdef to only allow certain code to be compiled on different platforms. 如果确实要执行此操作,则需要将平台特定的代码放入#ifdef内,以仅允许某些代码在不同平台上编译。 It might be easier to create one common C library that will be the same across platforms and then three separate C libraries that handle platform specific code. 创建一个在各个平台上都相同的通用C库,然后再创建三个用于处理平台特定代码的C库,可能会更容易。

I think the code would be easier to read and manage this way. 我认为代码更容易阅读和管理。

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

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