2

I created a static library which internally contains another static library (X) inside "Link Binary With Libraries" folder. But when I export my library to a sample project and try to compile it fails to locate the X library path. I am adding "." in the "Library search path" build parameter while building my static library.

What is that I am missing here?

2 Answers 2

2

If I understood your issue correctly, then it is less a linker-search-path problem but more a conceptual problem.

I see two options for solving the issue:

The common and straight-forward solution;

  • add both static library projects into the project of your app
  • expand the included projects
  • expand the Targets of your app-project
  • expand the "Link Binary With Libraries"-Entry
  • drag the product files of your library projects (actual libraries) down into that "Link Binary With Libraries"-Entry
  • include the header-path to both of your library-projects within your USER_HEADER_SEARCH_PATHS build settings

The next approach is rather unconventional and in most cases just not worth the extra mile. Here comes some explanation before going into the details.

The concept of a static library basically is a bunch of object-files stuffed into one single file (archive). Linking a static library against another static library is rather uncommon - well, to spell it out correctly, impossible.

...but then again, nothing is impossible when it comes to coding ;)...

The wrapper-library solution;

  • use ar to extract all object files from all the libraries you want to combine
  • use ar to combine all those object files into one big, new library
Sign up to request clarification or add additional context in comments.

8 Comments

The first option looks good to me and in fact I tried going that way but facing issues there. This is how I am doing it: Creating my own static library & header file and putting them inside the Frameworks folder in XCODE of the project where I want to use it. Along with my static library I also put other static libraries directly in Frameworks. These were the libs I wanted to put inside my static lib. Finally in the build settings for this project I am setting "Header Search Path" to the path of these libs.
After doing the way I described as "The common and straight-forward solution", what is the exact linker error message?
When compiling I am getting this error: Undefined symbols for architecture armv6: "_OBJC_CLASS_$_MyLib", referenced from: objc-class-ref in TestAppDelegate.o ld: symbol(s) not found for architecture armv6 collect2: ld returned 1 exit status
Many possible issues, NOT a search-path problem. Make sure your libraries are compiling with the "Build Active Architecture Only" set to NO.
After seeing your edited comment, I a starting to doubt that you actually followed my first option hints... no need to copy anything, just reference the libraries within your project as drafted.
|
2

ALong with setting up Header Search Path , Try setting up the Other Linkers Flag too..

Go to “Other Linker Flags” under the “Linker” section, and add “-ObjC” and “-all_load” to the list of flags

Hope that works for you,

1 Comment

Both of those mentioned flags are only useful if the library/ies contain categories on elsewhere implemented classes. Actually, since clang 3 only -ObjC is needed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.