简体   繁体   中英

How to use c static library in iOS app?

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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