Static library's Prefix header not referred - objective-c

I have define some default values in My static library's Prefix header and using in a category. When I compile the library stand alone it compiles fine. but when I attached the library to a projects it compliance variable not defined. I am pretty sure I have missed something when I attaching library.
This is how I attached the Library - I dragged and dropped static library project on to the new project and added dependency. I am wondering what was my mistake.

Go to Build setting of the main Project(not the static Library).
Search for "other Linker Flags" add -ObjC
You have to add this flag in the targets as well.
some other useful flags description for static library
-all_load Loads all members of static archive libraries.
-ObjC Loads all members of static archive libraries that implement an Objective-C class or category.
-force_load (path_to_archive) Loads all members of the specified static archive library. Note: -all_load forces all members of all archives to be loaded. This option allows you to target a specific archive.

Related

cmake target_link_libraries - unwanted target

I have a problem with cmake target_link_libraries.
I have 3 libs. The first is static compiled, the second one (shared lib) link to it and the third one is an executable which use the second lib.
My problem is that my first lib is automatically added to the third lib and leads into a "object already defined" problem.
Is it possible to hide away the first lib from the third one?
I use cmake 3.4.x
Compiler: msvc 2010 x64
Thanks in advance
Tonka
Your third "lib" isn't a library, but an application. You need to add this using add_executable, not add_library.
If your shared library links in a static library, and then you want to link an application to both the static library and that shared library, you get two copies of the static library. Never link static libraries you plan to use elsewhere into a shared library, for this reason. Either make the first shared as well (the name implies that's what you want, as it is exactly what you are describing), or a workaround for this design problem could be to not explicitly link the application to the static library.
I've solved it. I can link to a library private, so f.e.
target_link_libraries(MyLib2 PRIVATE MyLib1)
will hide MyLib1 from everybody linking to MyLib2

Xcode: automatic link static library dependency to Project

I've workspace with two project: static lib and cocoa application. Static library link some system frameworks(libcrypto.dylib) and include dynamic lib's .h files(openssl/bn.h openssl/rsa.h). My static library compiles successfully.
Cocoa application uses this static library and at compile time gives an error: "undefined symbols, symbols not found" (bn, new rsa etc).
But when I include libcrypto.dylib also into cocoa application project then there is no error.
Question: Xcode can do this automatically, by taking dependency from the static link library?
Thanks.
The answer is unfortunately no. It is common practice to include each single static library in the project that requires the code. That is just the way it is done.
There is an interesting article on how to handle multiple static libraries in an XCode project.

Using iOS Static Libraries without adding .a Files

We can use iOS Static Libraries without adding header files into the project.
But i want to use the Static Libraries without adding .a files into the project
Finally, I found the solution
Path of the static library should be added in ->target->build settings-> Other Linker Flags
eg.)
/Source/iPhoneApp/libs/Connection/build/Debug-iphonesimulator/libConnection.a /Source/iPhoneApp/libs/SocialNetwork/build/Debug-iphonesimulator/libSocialNetwork.a
If you built the library, you can use dependencies to add the library project to your app project without the hassle of configuring stuff.
To do so, just drag the .xcodeproj file from your library to the app project, go to the app target properties, and add a dependency on that library, just as you'd add a public framework such as MapKit.

Multiple Libraries and -ObjC flag

I have a three Objective-C libraries and an Objective-C application.
The application uses library A, library B and library C.
Library A uses library B.
I need to link library C to the project with the -ObjC flag.
(All libraries are static cocoa touch libraries)
But then i get the problem that I get a compiler warning for dubplicate symbols in library B.
When I leave out the -ObjC flag the -ObjC flag, library C is not used properly.
How can i solve this?
Thanks
You can add
force_load
with path to library needed to be loaded with -ObjC
from linker man:
-force_load path_to_archive
Loads all members of the specified static archive library.
Note: -all_load forces all members of all archives to be
loaded. This option allows you to target a specific archive.

CMake: add static library to shared lib

I would like to create shared library with cmake, but also I need to link it to third party static libraries.
For example if it should include my own file1.o, file2.o, then statically linked libfoo.la and then be written down to disk as .so file which dynamically linked to libbar.so
Is it even possible?
It is possible to link static library to shared library. On most Unixes, you will need
to add -fPIC flag or its equivalent for producing position-independent code when you build static library. On Windows, there is no PIC, i.e linking static to shared just works out of the box.