Iphone Link Static Library - iphone

I have created a static library in XCode called TestLib.
I then created a simple test project that will use this library. I dragged the TestLib xcode project into my test project (frameworks section - if it matters), and set TestLib as a direct dependency of the test project.
I am having trouble importing header files from the Library, I only have 1 in there (its a test project) called TestLibHeader.h, but no matter how I attempt to import them, I get compile errors stating that the header file cannot be found.
Where am I going wrong?

You need to tell your build target where to look for the header files for a given build configuration.
in XCode 3.x
Double click on your build target.
Click on the Build tab.
Search for the build setting Header Search Paths
Set Header Search Paths to include the path the header files in your library project.
See the instructions for setting up three20 as a dependency for a good example of these steps in action.

Related

Suddenly headers in headers not found <module-includes>:1:9: note: in file included from <module-includes>:1: Xcode

I have been working for a while on a project that implements a custom framework that uses a C library. The framework is written in Swift and I created a module to expose the C headers to swift. The framework was started in a different project, the framework project was then copied to the root of my app project and it was added to my app project as embedded binary. By doing that I aimed to develop the framework, which it is a git submodule of my app project, while I was coding the app.
The framework, as I said, uses a C library and I have the .a files for both debug and release and it provides with a headers include folder. So in my framework project I have the following structure:
and for the static libs
The static libraries where imported as framework and the "library search path" modified for using debug or release. The header search header path was also modified by adding the root folder where all the includes are located.
The Module is located in a folder inside the product folder and defined as:
So that has worked until today. Maybe it was wrong but it never complained.
So the headers are found but the headers inside the headers can't be found.
What am I doing wrong?
I have tried to include as many information as I could. I hope it will be enough.
Thank you.
Well, I think what caused the problem. If I am wrong please let me know.
I have figured out that in "Swift Compiler -> Import Paths", which where I declared my OHNet Module path, you also need to declare the root folder for the "imported headers" so:
Clean and Build and the error is gone.

Can't link static library in XCode 4 in workspace

So, I'm working on a project and can't get my XCode 4 workspace to behave. I have the main application as one project in the workspace. I then add the static library project into the workspace. It seems like everything is working okay. I can import files from the other project. It builds, but when I run it, I get this:
dyld: Symbol not found: _OBJC_CLASS_$_iGBC
Referenced from: /var/mobile/Applications/CD00CC83-28E4-4467-96C0-0D1777E21FDA/GBA4iOS.app/GBA4iOS
Expected in: flat namespace
in /var/mobile/Applications/CD00CC83-28E4-4467-96C0-0D1777E21FDA/GBA4iOS.app/GBA4iOS
And crashes. It appears that although Xcode believes the library has been linked, and it builds and runs, the app doesn't actually have the library. But in the derived data folder, it looks like everything that should be there... is there.
I'm going insane with XCode and all it's nuances in settings. Are there sanity checks I can go through to ensure this is working properly? What else can I do?
Edit:
Project settings are valid, and I've already linked the libraries.
Edit 2:
My workspace is setup so the libraries are also in the workspace:
I have removed the lib.a file from the main project and removed it from the Build Phase section, and added it back numerous times. There is no "copy library into destination folder" option when adding it in this way, so I can't do that.
try clean your build, if it don't work, remove the library in build phase and your project folder. When adding the lib to your project, check "copy item to destination if needed", the add that lib in build phase.

How to build ZBar SDK with the project instead of using the static library?

I am building an iOS, code scanner project using ZBar SDK. I am trying to build my project directly from the source of ZBar, rather than including the libzbar.a static library.
I have downloaded the ZBar source which includes the XCode project to build libzbar.a. I tried copying all source files from the project but it didn't work. I keep on getting undefined symbol errors.
What source files should be included, considering that I need to support only iOS?
Should the folder structure be strictly followed to build the project?
Would there be any need of build settings if I direcly include the source files?
EDIT:
I followed the same folder structure and build settings used in the XCode project of libzbar. I have managed to build the library but it's still failing while linking. I get the error: ld: duplicate symbol _OBJC_METACLASS for all the source files. I have double checked, there are no references to the original libzbar.a static library in the project or more than one occurrence of these source files. If I remove the references for them, the project builds fine, but then fails whenever any symbol from the library is referenced. I think I am still missing something!!
I have solved this problem finally. Here are the steps that I did:
1) Copied the source files of the project to my project.
2) Removed the dependency of libzbar.a from my project.
3) Added the path to the folder containing the source and headers to the Header Search Paths build setting of the project.
4)Added the following user defined build setting to the project:
EXCLUDE_SOURCE_FILE_NAMES
GCC_MODEL_TUNING
PREBINDING and
USE_HEADERMAP
You should create the static library your self from the source code then add the output static library to your project, or link the projects together and force a build of the static library before your project is build.
After downloading the zip file from the default Mercurial repository and opening the file in xCode, click on the "EmbedReader" part of the target selection drop down box and switch to "zBarSDK"
Once you switch to the zBarSDK, just build from the product menu and you should have your static library file....
I used ZXing lib before and it integrated well. It was included as a project and main project has target dependency to build it before main project. I edited it's sources for my needs and have no problems working with it.
I used this tutorial. It can be helpful for your needs too.

iphone - ".../libtool: can't locate file for: -lxml2"

I have a 2 projects in an xcode workspace. One is a static library and the other one use the static library.
In the static library I added the GDataXMLNode.h and GDataXMLNode.m files, which I use in the main project. The GDataXMLNode.h is a public file so it's visible in the main project. I also linked the target of both projects with libxml2.dylib. And I also include in the Header Search Paths and User Header Search Paths the location /usr/include/libxml2.
Although these, I get an Apple Mach-O Librarian Error:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: can't locate file for: -lxml2
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: -lxml2 is not an object file (not allowed in a library)
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libxml2.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libxml2.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool failed with exit code 1
Do you know how can I fix this?
I had the exact same error recently. As you found, removing "-lxml2" from the "Other Linker Flags" in Build Settings helped resolve the errors. This is true when you are building a static library. You will need to include that linker flag ("-lxml2") in any target that actually includes your static library. For example, if you created unit tests for your static library as I did (i.e. MyStaticLibraryProjectTests) then you would need to make sure to add the linker flags to the MyStaticLibraryProjectTests target but not to the actual MyStaticLibraryProject target. More often than not I generally forget to select a specific target when I go to look at my Build Settings tab. I usually assume that if I click on the big blue project icon that the build settings are just for the entire project but it is very important to select the correct target when modifying those settings.
Early on most projects generally do only have a single target but as you get more advanced it is possible to have multiple targets for each project. Hope that helps.

Libxml in a library for ios

I have created a cocoa touch static library that contains functionality that I want to include in several apps. This library is linked to libxml and I have the header search path /usr/include/libxml2. The library builds correctly.
I include this library in another xcode project as a reference (by dragging the library xcodeproj file into my app xcode project. I also setup the target to have the library as a direct dependency, setup the header search path to include /usr/include/libxml2, and add libxml2.dylib in the frameworks.
The problem is, when I try to build the project is has a build error:
Libxml/tree.h: No such file or directory.
I initially had this problem trying to build the library and solved it by adding the header search path and framework into the project for libxml2.
Incidentally, i have another app that uses the library but does not use libxml, it builds and runs correctly.
So the problem seems to be using libxml in both the app and a linked library.
Anybody any ideas?
Yours hopefully,
Neil.
You probably need to add the include path /usr/include/libxml2 to both the target and the project.
To add it to the target, right click on the target and select Get Info.
To add it to the project, go to the Project menu > Edit Project Settings.
In both cases, make sure you've selected Configuration: "All Configurations".