16

I'm developing a C++ project by using Xcode 4.6.1 as IDE. Now, I'd like to add a static library mylib.a and the related header mylib.h.

I read about this solution, but it doesn't work (while clicking on Target Dependencies, the box is still remaining empty).

Is there a way to achieve this task?


UPDATE:

I created a group, then I added the file mylib.a on it. It seems to work fine, but at compile-time a warning as follows appears:

ld: warning: ignoring file /Users/vdenotaris/Desktop/Code/MyStaticLib/mylib.a, file was built for archive which is not the architecture being linked
(i386):/Users/vdenotaris/Desktop/Code/MyStaticLib/mylib.a
Community
  • 1
  • 1
vdenotaris
  • 13,297
  • 26
  • 81
  • 132
  • possible duplicate of [How to "add existing frameworks" in Xcode 4?](http://stackoverflow.com/questions/3352664/how-to-add-existing-frameworks-in-xcode-4) – jww Jul 03 '14 at 05:33
  • possible duplicate of [How to add .a C static library to Xcode and use it there?](http://stackoverflow.com/questions/11830434/how-to-add-a-c-static-library-to-xcode-and-use-it-there) – eonil Jul 03 '14 at 06:11

1 Answers1

17

Target dependencies is used if your static library is created by another XCode project and you want to include this project, so that you can easily develop on both you library and the corresponding application.

If you want to include a foreign library you would select your target under TARGETS there you select the section Build Phases there you have the area Link Binary With Libraries into this area you would add your library either with drag & drop or with the + sign.

To add the include path you select your project under PROJECT there you select the area Build Settings there you have under Search Path the Points Header Search Paths this should include the path to the directory where the header is.

The difference between the settings in Project or Targets is that in Project it sets the default settings for all targets. In Targets you can change the settings per Target.

EDIT For the linking errors this two answers could be helpful:

Community
  • 1
  • 1
t.niese
  • 39,256
  • 9
  • 74
  • 101
  • 1
    Thank you so much for the answer. I linked inside my project `mylib.a`and `my lib.h`; now, when I build, appears the following warning: `ld: warning: ignoring file /Users/vdenotaris/Desktop/Code/MyStaticLib/mylib.a, file was built for archive which is not the architecture being linked (i386): /Users/vdenotaris/Desktop/Code/MyStaticLib/mylib.a`. How can I resolve this error? – vdenotaris Apr 12 '13 at 14:41
  • @vdenotaris are you developing an iOS app ? – t.niese Apr 12 '13 at 14:45
  • No, I'm developing a C++ app for my Master's Thesis. – vdenotaris Apr 12 '13 at 15:06
  • please show the _Architectures_, _Valid Architectures_ and _Supported Platforms_ for both you static library and application. – t.niese Apr 12 '13 at 15:09
  • 1
    I suppose that the considered static library was built for x64, whereas my project is based on i386 arch. – vdenotaris Apr 12 '13 at 15:12
  • i thought it is your own library, cause of the path, if it is not your own you can check it in command line with `lipo -info /Users/vdenotaris/Desktop/Code/MyStaticLib/mylib.a` – t.niese Apr 12 '13 at 15:23
  • `input file mylib.a is not a fat file` `Non-fat file: mylib.a is architecture: x86_64` – vdenotaris Apr 12 '13 at 15:28
  • so your guess was right, the linking error is because your project is `i386` and the library is `x86_64` – t.niese Apr 12 '13 at 15:29
  • Yes, I just now rebuild OpenCV (used inside my project) to support x86_64 arch and all works fine. Thank you so much. – vdenotaris Apr 12 '13 at 15:35