Akhil K Nambiar
Akhil K Nambiar

Reputation: 3975

Objective C Library and Search Path

I created a static library in Objective C (for OSX) for performing some calculations. I then compiled it and included it in another project. Later on I'm not able to use it in my codes.

1> When I wrote

import "Auth.h"

it was giving me a File Not Found error. Why is it so?

2> Then I had to set the search path to the source of the libraries and it got compiled and executed correctly. Does that mean I can't reuse the compiled library with other projects without distributing the source code along with it?

3> I thought if Search path is being specified then the compiled library won't need to be needed. So I deleted the library. But that didn't work. It means source + the library both are required.

What is actually happenning. I just want to distribute libAuth.a with other teams for the project without giving out the source. How can I do that.

Upvotes: 1

Views: 645

Answers (2)

Engnyl
Engnyl

Reputation: 1380

Try adding the followings in your main project target settings;

”-ObjC” and ”-all_load” to Build Settings > Linking > Other Linker Flags, ”$(TARGET_BUILD_DIR)/usr/local/lib/include” and ”$(OBJROOT)/UninstalledProducts/include” to Build Settings > Search Paths > Header Search Paths, "$(BUILT_PRODUCTS_DIR)" to Build Settings > User Header Search Paths.

Upvotes: 1

trojanfoe
trojanfoe

Reputation: 122391

You just need to provide the library file (.a) and the header files; the source files can remain private and undistributed.

Be sure to compile the library for all architectures (x86_64 and i386 on OSX) that can possibly use the library, using lipo to create a fat binary .a file.

For example:

xcrun --sdk macosx10.8 clang -arch x86_64 -o file1.o file1.m
xcrun --sdk macosx10.8 clang -arch x86_64 -o file2.o file2.m
xcrun --sdk macosx10.8 libtool -static -arch_only x86_64 -o libmystuff_x86_64.a file1.o file2.o

xcrun --sdk macosx10.8 clang -arch i386 -o file1.o file1.m
xcrun --sdk macosx10.8 clang -arch i386 -o file2.o file2.m
xcrun --sdk macosx10.8 libtool -static -arch_only i386 -o libmystuff_i386.a file1.o file2.o

xcrun --sdk macosx10.8 lipo -arch x86_64 libmystuff_x86_64.a -arch i386 libmystuff_i386.a -create -output libmystuff.a

Upvotes: 1

Related Questions