How to use c static library in iOS app?

删除回忆录丶 提交于 2019-12-10 12:23:25

问题


I have library header files and static library compiled with XCode SDK from C sources. How to use it in my iOS app? I believe i have to add .a file in the project settings (link section) and header files in source files settings. What about using .mm files instead of .m? How to wrap C API to Objective-c correctly?


回答1:


You don't need to use .mm. This is only for Objective-C++ files.

All you need to do is include the .a and .h files in your project (I think you can just drag and drop) and then #import the .h files in the files you want to use the library in.

In older versions of Xcode you had to manually make sure the .a was being linked, but I'm quite positive that this is handled automatically now when you drop the library into the project.

If drag&dropping isn't working, you can right click in your projects list of files and click "Add files", which will open a finder window. From here, navigate to the .a and .h files, select them all, and include them.




回答2:


When using C in objective-C, there is no need to really do anything except use the C code. This is because Obj-c is a superset of C, which basically means that any c code you want to use, you can use it with obj-c. .mm is for objective-c++, which is where you will have the ability to use all c++ code.

When using the library, just put the .a file within your project settings, and then in your .m, or .h file, just #import <.hfiles> and that should work...



来源:https://stackoverflow.com/questions/23970500/how-to-use-c-static-library-in-ios-app

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