Linked Static Libraries are NOT Rebuilt Together with Main Project - ios

In my workspace I have 2 projects: my main project, and a static library project. I link the resulting .a of the library project into the main project. Problem is, when I make a change to a source file in the library project, and run the main project, the library project does not get rebuilt, and the old .a library gets used. This leads to strange runtime errors.
Is there a way to enable correct compilation of dependency projects?

This is a bug in Xcode there for ages.
Workaround:
In Project Navigator find the reference to the library .a file in the main project.
In Utilities pane, change to "Relative to Build Products"
Edit project.pbxproj and find the line the static library lib*.a
file is referenced by "path=...".
Remove the path, so just lib*.a is left.

Related

How to make XCode add the linked project headers and implementaion files to the static library and framework

I have a static library project and in that project I linked a .xcodeproj to the source code so I can update easily actually and to not copy and paste files in the static library project for easy update.
The purpose thought it's to embed this .xcodeproj with my code into the result static library or .framework that I will build using a script.
Although I can see that there is nothing added in the compile sources or the copy header files which I added. If I try to add with drag and drop files from the linked project to my static library build phases copy header section it copies the file to my project again, but I don't want this.
And if I add a header file #import to one of my public headers and try to use the static library to the client project it complains that the header is not found!
So, in the end, what I want is the whole linked project files to be copied in the resulting static library or .framework with the scripts and target I have.
Is this possible to achieve, I think I miss some project setting that I'm not aware about that will see and copy all header and implementation files to my result static library or .framework?
Is my approach overall correct? I don't think that there is no option to use a linked project in a static library and embed it when the build is happening since I am using it in my project!
I could add the .framework of the third party component too and merge to my static library. I have created this question earlier today. Is it possible to include a .framework in a .framework and how?
Regards.
Not sure if your #import-not-found issue is a linker issue, but...
Make sure to use the -ObjC flag in "Other Linker Flags" in the library's Build Settings. This gets the linker to build everything in the library.
Mentioned here:
https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/configuration.html
And also make sure you link in the library in the build settings for the project that needs it.

Static Library import

I created a static Library but I am unable to import it. Here are the steps that i followed to add it to my project.
1) From finder, I dragged my library .xcodeproj into my main project.
2) I selected the main project, went to target and then build phases.
3) I added the library under Link Binary With Libraries and Target Dependencies.
4) Under Build Settings -- Header Search Paths, I added $(BUILT_PRODUCTS_DIR).
5) I also added -ObjC to Other Linker Flags.
However when I try importing the library, it's not being recognised.
Can anyone help with this?
You can include library by two ways either u can drag and drop library.xcodeproj into your project or you can include .lib file into your project. It might be possible that your lib file was not build properly.
You could build ur lib file by opening ur library.xcodeproj in xcode select build target as iOS Device and build the project.
If build is successful u could find the newly created .lib file to the following path LIbrary/Developer/Xcode/DerivedData now remove the previous lib file and include the new lib.

Xcode subproject framework dependency build fail

I have one Xcode iOS project (I'll call it the super project) which contains another Xcode iOS project as a subproject.
The subproject is an iOS static library. I have done everything described at http://www.blog.montgomerie.net/easy-xcode-static-library-subprojects-and-submodules.
So, the static library is listed as a target dependency under the super project's target's build phases.
The static library is already linked as a binary library in the super project's target's build phases. In a class in the super project, I am able to reference classes in the subproject but when I try to build the super project I get tons of errors for undefined symbols.
These "undefined symbols" are classes in the frameworks that the subproject (static library) depends on. My question is, how do I get the super project build process to be able to locate the header files of the frameworks that the subproject depends on?
I assumed that linking the static library would have handled this unless I'm doing something else wrong. Just for the heck of it, I also tried linking all of the frameworks that the subproject depends on as binary libraries to the super project.
This got rid of all the errors but then the build still failed because it says there were 33 duplicate symbols (because now both projects are linking the same frameworks).
I do not think that the super project should have to link the subproject's framework dependencies. Thanks in advance.
I think your problem is that the superproject do not find all the static library headers when the build fails with tons of "undefined symbols" errors.
Have a look in superproject settings panel, under build settings tab. Find "header search paths" and "user header search path" (or something similar) and put inside them the path of subproject headers folder. If you put /** at the end of the path, xcode will search inside all the subfolder of the path.
Make sure the "always search user header search path" flag is on/true.

how to enable xcode precompiled source files

guys,
I was using xcode to start a project which links to a static lib project.(I add the project as the child of the target project and add .a to the target)
Every time, I run the target, it has to recompile all the files from the lib project whether or not the source files in the static lib project has changed.
How to stop it from recompile the static lib project? Thank you.
I don't have a straight answer to your question but i run through this blog with a step-by-step instruction to create a static lib in XCode. I have tried myself to see if the static lib was rebuilt when i was just editing the target project but it didn't seem to occur.
Few hints to consider:
Check the scheme you are using when building your target (Parallelize
Build and Find Implicit Dependencies should be both turn on).
Make sure you don't clean your lib project.
you can also construct your own framework and use this projects. I did it using this link

Build a static library for iOS - specifically spatialite

First, please forgive and point out if I am to use some other protocol for referencing another thread/post.
There was a previous thread how to compile spatialite for iOS where the top answer partly described building spatialite as a static library for iOS. The answer included the text:
"Once you've drag n drop the .a (both are required to work in the simulator AND on the real hardware), you can initialize spatialite by just invoking spatialite_init(1)."
I am guessing this is translated to some version of the following?
Xcode 4
File->New->New Target->iOS->Framework & Library->Cocoa Touch Static Library
Name the library - libSpatialite_TedS
Drag the header files to libSpatialite_TedS -> Copy Headers (question here ... there is a spatialite.h file in the 'headers' directory of the 'spatialite2.3.1.zip' download. Then in the subdirectory 'spatialite' there is another spatialite.h that is not an identical file and is obviously needed. Do we just drag the header files from 'headers' directory, then drag the directory 'spatialite' as a directory into 'Copy Headers' area of our Xcode static library 'myNewLibrary'?)
Drag the '.a files' libSPATIALITE2.3.1_arm.a & libSPATIALITE2.3.1_x86.a
Shouldn't we have some '.m' files to go with these headers in the 'Compile Sources' field?
Now, without referencing the libSpatialite_TedS in my project, when I 'Command-B' to build, the project build succeeds. However, when I look for the compiled product in
/Users/Admin/Library/Developer/Xcode/DerivedData/MyProject-gutnkbwqqonzgxbcmfzzzkadqhid/Build/Products/Release-iphonesimulator
I see build's products, but they do not include libSpatialite_TedS.
Is this because the compiler is 'smart' and recognizes that none of the header/.a files are referenced in the project so it does not bother compiling them?
And, is this the correct way to go about achieving the objective of the original poster how to compile spatialite for iOS?
Many thanks,
Ted S
I was running into linker errors with the original poster too, but solved it by including libsqlite3.dylib, libstc++.dylib, and libiconv.dylib in the target.
Hope this helps!
Ted, I believe that the .a (static library) files and headers are meant to be used in a project right away, rather than in another static library as you've described. They are the result of a project's output. I think you can find the project that built them, here:
http://lionel.gueganton.free.fr/spatialite/
And a little more on static library files:
What is a .a (as libcrypto.a) file?
EDITED
Here's another link that you might find helpful. It s a summary of the Static Library build process in iOS:
http://www.icodeblog.com/2011/04/07/creating-static-libraries-for-ios/

Resources