Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking a Static C Library in Xcode 7?

I'm currently trying to link a static C library I've created to a fresh Xcode project. To link it, I followed the following instructions:

1) Navigate to Build Phases

2) Expand Link Binaries With Library

3) Added an "other" library, and then specified the .a file in question.

Unfortunately, the project won't compile and throws the following error:

ld: library not found for -ltxht

I'm not sure exactly what to make of this. The library seems to appear okay in the project as a project file, and I can't find any indication that there is anything wrong with that.

I've tried setting it's location to Use Absolute Path in the file-inspector, but that didn't change anything.

I've also seen that in some similar online posts that somehow providing the full path to the static library might help resolve the problem:

In reaction to your comment on Eduard Wirch' answer: you can also control static linking for this one library only, if you replace -lhdf5 by -l/full/path/to/libhdf5.a

From this SO Post.

However, I'm not sure how to do this? I've gone into Build Settings and seen nothing but pages of options, but there isn't much under Headers or Linking that seems to allow me to do what I want.

Can anyone explain how to correctly add this static C library? Just for your information, the location of the project relative to the location of the library is as follows:

Library: /lib/libtxht/libtxht.a Xcode Project: /lib/libtxvm/myProject.xcodeproj

like image 459
Micrified Avatar asked Sep 22 '16 21:09

Micrified


People also ask

Is XCFramework static or dynamic?

An XCFramework can be either static or dynamic and can include headers.

How can I use an .a static library in Swift?

Yes, you can use static libraries in Swift. Go to your Build Phases and under "Link Binary With Libraries" and add them there. Alternatively, you can go under Build Settings and in "Search Paths" append the "Library Search Paths" value to include the path to the folder that your . a file is in.


1 Answers

If this is an external static lib, you need to add the path it exists to Library Search Paths under Build Settings. Not the full path, just the directory it is in.

like image 75
Mobile Ben Avatar answered Sep 28 '22 15:09

Mobile Ben