Adding 3rd Party to Static Library - iOS - ios

I'm following the tutorial given here to create a static library for my application. The static library relies on a 3rd party library in return. I followed method 2 and when I compiled the program it throws me the "header file not found error" as shown here
I have uploaded my static library and my application project for your reference. Any help on that?

When you use any static library you also need header files of that static library. Follow this
1. Copy header files to your project directory (No need to add them to project).
2. Go to Build Setting -> Search paths
There is option "Header Search Path" add path where your header files folder exist. If your header files are not under one folder then set top folder as search path and set as recursive this will recursively search for your header files.

Related

How to create a framework from a C library with nested headers

I want to create a iOS framework for a popular C library.
My Current Setup:
This is what I'm doing:
Build the library for iOS and iPhone simulator architectures
Combine the two archive .a files into a single fat library using lipo
Use libtool -static -o to get the final library
By this stage I have a binary and a bunch of header files. In xcode:
Drop the binary (from step 3) and ensure its linked under: Target > General > Framework and Libraries, and Target > Build Phases > Link Binary with Libraries
I copy all the header files from the C library and place them under dir Dependencies/myClibrary/include/. The include dir contains a master header file myClibrary.h which includes a number of header files from ./abstract/*.h.
At top level of the xcode project dir, I also create a module.map file with content:
module MyWrapperFramework [system] {
header "Dependencies/myClibrary/include/myClibrary.h"
export *
}
Add all header files to xcode and for each header file, under Target Membership change value from project to public.
Build
Testing the framework in an App
I am able to build the framework, with settings as mentioned above. However, when I want to test it in a test Objective C app, I import the framework and call functions related to the myClibrary. On building the app, I get the error:
'myClibrary/abstract/headername.h' file not found
The above error originates from myClibrary's master header file myClibrary.
Most of the tutorial that I could find deals with C libraries having a single header file. How can I create a iOS framework from a C library that contains nested header files?
In case, nested header files are not the main issue here, what am i doing wrong?
A framework's headers get installed in the Headers directory inside the .framework. The compiler knows enough magic that when you say #import <myClibrary/myClibrary.h> that it will start the search for myClibrary.h inside that Headers directory.
As a result, the default public header build rules are to copy all public .h files (no matter their position in the source tree) into that Headers directory. That directory should be set as the $PUBLIC_HEADERS_FOLDER_PATH variable during building.
It seems as though you need to install headers into different directories. You could simply set the value of the Public Headers Folder Path in build settings to be a subdirectory, which will then install all public headers there. You could then have a custom Copy Files build phase to install just the single, overall header into the original headers directory.
Or, you could just add just the headers which go into the root as public headers, then have a custom Copy Files phase for all the rest, which copy them into a custom subdirectory. I think if you choose "Wrapper" as the destination, that is the root of the framework, so if the subpath is "Headers/abstract" that should work (though I have not tested myself). If you need to have multiple subdirectories, you would need a custom Copy Files build phase for each one.
Or, of course, have a custom build script to copy the headers more manually, if that's easier than multiple build phases (say one that copies all files in the include directory to $PUBLIC_HEADERS_FOLDER_PATH but preserving the structure, if there are a lot of subdirectories).

xcode static library public/private/project header files

So, I have an iOS app project with a static library as subproject. As found multiple times here on SO, you should set the visibility of the library header files to public/private/project, depending on who should be able to use them.
Based on that, I created one class with a header file that exposes functionality to the app project (or whoever is going to use this library). Naturally, this header file imports a number of headers from other classes inside the library project. As these other header files do not provide functionality that should be exposed to the library's users, i would like to set these to "project", making them invisible to the rest of the world.
However, when i set header files to "project" they don't get copied into any of the private or public header folders. This results in a 'ProjectHeader.h' file not found error when using #import "ProjectHeader.h" in the PublicLibraryClassHeader.h when compiling the app project that uses the library.
So the question is: How can I set header files to "project" in a library project and stil use them from within that library project? Am I misunderstanding the concept of public/private/project header files in static libraries?
The easies way is to convert your static library into framework. Framework is a static library in a specific container, that does all magic for you. Btw, this words about public headers are related to frameworks, not to static libraries.

Import a static library as a subproject

I watch this video to know how to create a static library, I just watched until the 4:05 minute video (which have already been enough to learn how to create a static library).
But I learned that there's another way to import a static library for the project called subproject, for this I open my iphone project and add my library project (MuitosAlertas.xcodeproj), Then I added two references to my library inside the tab Target Dependencies and Link Binary with libraries as you can see below:
When I compile and run, Xcode give me the problem
Lexical or preprocessor issue 'MuitosAlertas.h' file not found
I try to put inside Other linker flags the code -ObjC but without results, how can I solve this problem
You must add Header Search Path to your target. In build setting search "Header Search Path" and add relative link to your static library project. How to add relative path read more here
You may need to search path with recursive option.
Once you have created your Library then make a build from the target added separately for the Universal support and then by right clicking on to the .a file from bundle navigate to folder and look for Universal and copy Include folder and your StaticLibrary.a file, then where you want to use it paste in that project and add reference to it and in bundle setting you need to set the HeaderSearchPath of the library where it is kept and the OtherLinkerFlag to -ObjC.
Then import the headers of your library and use your methods.

How to import a customer static library into Objective C project?

I have created a static library using Objective - C and generates a library called: libDummy.a, with header called ClassOne.h and ClassOne.m, then I need to add this library into another project, but it keeps reporting "libDummy/ClassOne.h" cannot be found.
And I have copied the libDummy.a to the same folder as the new project, also I checked the Search Library path, it's pointing to the correct folder, but the problem still exists.
Any idea about how to fix that?
try this,
1) Remove all the files and re-add them to project bundle, but dont forget to select as shown in below image,
2) Recheck library path again and add.
Link the library file in build Phases
Xcode->Build Phases -> Link Binary with Libraries
Add your .a file here.

iOS: Clarify different Search Paths

There are three different search paths in XCode Build Settings:
Framework Search Path
Header Search Path
Library Search Path
Could anyone clarify what those paths do and what they are used for?
Framework search path: where to search frameworks (.framework bundles) in addition to system frameworks paths. Not used very much in iOS development, officially there is no developer iOS frameworks.
In Mac development, it's set automatically if you drag a 3rd party framework into the project. Otherwise, just set it to the container directory where you saved the framework.
In xcconfig files you use this variable:
FRAMEWORK_SEARCH_PATHS = "/path/to/frameworks/container/directory"
Header search path: where to search for header files (.h files) in addition to system paths. Usually you'll need it if you are using a 3rd party library. Set it to the directory where you have the header files. If you use a directory to include the header (example: #import "mylibrary/component.h") set it to the parent directory.
In xcconfig files you use this variable:
HEADER_SEARCH_PATHS = "/path/to/headers/container/directory"
Library search path: where to search for library files in addition to system paths. Xcode will set it automatically if you drag a library (.a files) into the project. To set it manually, use the directory where the library is located.
In xcconfig files you use this variable:
LIBRARY_SEARCH_PATHS = "/path/to/libraries/container/directory"
All three can hold a list of paths, with quotes, separated by space.
These are used for searching for Frameworks, Header files, or Libraries that are not in the system search paths (like QTKit.Framework, standard C++ header files, etc).
My most common use for this is using the boost header library (*.hpp) files in my code I add the relative path "../lib/Boost/1.46.1" to the Header Search Path.
I find it better to add this at the project level instead of in each target. That way the targets inherit this and it only needs to be changed in one place if I update the version of boost.

Resources