简体   繁体   English

在Xcode iOS项目中使用C ++静态库(CCFits)

[英]Using a c++ static library (CCFits) in Xcode iOS Project

I am trying to using the CCfits library in an iOS project. 我正在尝试在iOS项目中使用CCfits库。 CCfits is a C++ wrapper to the c library cfitsio. CCfits是c库cfitsio的C ++包装器。 I have the source code to both of these, and also have them built as static libraries (.a files). 我拥有这两个代码的源代码,也都将它们构建为静态库(.a文件)。 I would like to add the CCfits library (libCCfits.a) to an iOS project but when I am confused on how to access the library classes from my iPhone source files. 我想将CCfits库(libCCfits.a)添加到iOS项目中,但是当我对如何从iPhone源文件访问库类感到困惑时。 I have the library added under "Link Binary with Libraries". 我在“链接二进制文件和库”下添加了库。 I understand that Xcode needs me to import a header file, but what is the proper way to attach the headers to the project? 我知道Xcode需要我导入头文件,但是将头附加到项目的正确方法是什么? Do I need to make a framework file somehow? 我需要以某种方式制作框架文件吗? Or is the .a file enough? 还是.a文件足够?

You can easily mix C++ and Objective-C using Objective-C++. 您可以使用Objective-C ++轻松地混合使用C ++和Objective-C。 In XCode just rename your .m files to .mm and it will recognize the files as Objective-C++. 在XCode中,只需将.m文件重命名为.mm,它将文件识别为Objective-C ++。 Then you can use the C++ classes in your Objective-C code ( some restrictions apply , but not many). 然后,您可以在Objective-C代码中使用C ++类( 有一些限制 ,但不是很多)。

Since Objective-C is an extension to C you can use C libraries in any Objective-C program easily. 由于Objective-C是C的扩展,因此您可以轻松地在任何Objective-C程序中使用C库。

See https://stackoverflow.com/posts/10156243/edit 参见https://stackoverflow.com/posts/10156243/edit

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

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