6

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

Community
  • 1
  • 1
Micrified
  • 2,632
  • 3
  • 30
  • 45

1 Answers1

5

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.

Mobile Ben
  • 6,653
  • 1
  • 19
  • 37
  • Thank you! It worked! However, I can't seem to use any of the header files inside the library. Why might that be? I've tried including them but Xcode just throws me an error. Linking the archive to a C file via terminal and then executing seemed to work fine with including the headers. Just can't seem to do it in Xcode. – Micrified Sep 22 '16 at 21:29
  • 1
    You need to adjust `Header Search Paths` to have the path to the lib include files. – Mobile Ben Sep 22 '16 at 21:31
  • 1
    @MobileBen. Did the same, but doesn't work for my project. My library is the PayTabs SDK library that ends in .a extension – zulkarnain shah Dec 07 '17 at 06:30
  • @zulkarnainshah sorry to hear it doesn't work for you. It's a little hard to diagnose based on your information. What errors are you seeing (eg. what is the linker error). You should be able to look at the linker output to see what all the arguments passed in are. From there you could see if you indeed have the proper paths. Note if your issues are headers, then you need to look at the compiler pass rather than the linker. I'm right now talking about the linker. – Mobile Ben Dec 07 '17 at 18:43