简体   繁体   中英

What is the correct way to link to a C library (.a) in XCode?

I found a 3rd party library that I would like to use in an iPhone project. The library is written in plain C. I compiled the library and have added the resulting .a file in to my XCode project. Meaning.. I dragged the file into the IDE and xcode made a reference to it.

I am new to xcode so my question is how should I actually link to and use this library? Should I be able to #include the headers accompanying the library and start using this? Do I need to provide xcode with some linker arguments?

If someone could point me in the right direction I would appreciate it. Thanks!

Update

Apparently for my example it really is that easy. After doing the above, I just included the header files into my project and started using the library. It appears to be working great.

As you found out, dragging it into Xcode is all you usually need to do. When you release the drop you get the sheet that asks if you want to copy it the project directory and also has the add to target table which by default has the target checked. Having the target checked is the magic part. Doing so causes the library to be added to the link build phase.

If you ever forget to check the target when adding or have a situation like you add a 2nd target and want some libraries with it while other libraries are with the first target, you can manage that by selecting the project in project navigator and then the target in the detail view. In the Build Phases tab there's the Link Binary With Libraries phase. It lists which libraries that target is linking against. You can add or remove libraries to it as needed.

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