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.
Related
I have an iOS static library.
As a matter of fact, I have four variants of it:
Debug-iphoneos/libopende.a
Debug-iphonesimulator/libopende.a
Release-iphoneos/libopende.a
Release-iphonesimulator/libopende.a
I want to link my iOS app against this static library using Xcode.
To do so, I go to Build Phases, and in Link Binary With Libraries, I click the '+' to add one, using Add Other.
Now I have the problem of which variant I should be adding. So I just pick one of the .a files, and hope Xcode is smart enough to find the others?
Anyways, if I do this, the linking fails saying it can't find libopende.a file.
So, is it even possible to do what I want, without first building a 'Framework' instead of a set of static libraries?
Ok, so when linking against a static iOS library, you need to know that:
It does not matter which .a file you add in the Build Phases - Link Binary With Libraries panel. Any of the four .a files will do, it only takes the file name, not its path.
To actually differentiate between library variants for Debug/Release Device/Simulator, you need to specify the correct library paths in the Build Settings - Library Search Paths.
As after release of Swift 4, Swift is supporting Static library. But when I am trying to make use of Static binary inside application, it showing error with undefined module.
We are creating SDK with modular structure with 15 framework one for each module, but as Apple suggest it is not good to add more than 6 dynamic framework(As dynamic linking slow down app launch time.).
So after support of static lib in Swift, we decided to convert it to static library and then create one dynamic framework which provide facade interface for all 15 frameworks.
I created one Static lib named StaticA an try to add it in Dynamic Framework, but it shows below error.
No such module 'StaticA'
I also set Defines Modules to Yes but it does not helping.
Is it possible to make Static library modular using Swift ?
If Yes, then suggest way.
Thanks
There's a few build settings you need to enable:
MODULEMAP_FILE = $(PRODUCT_NAME)/module.modulemap
SWIFT_INCLUDE_PATHS = $(PRODUCT_NAME)
DEFINES_MODULE = YES
The other option which works (without modifying the build settings) is to copy the modulemap file to the products directory under include/$(PRODUCT_NAME)
Note:
I generally put the modulemap in the top level of the module directory
i.e. one level down from the xcodeproj file:
StaticA.xcodeproj then I would have at StaticA/module.modulemap
What this allow's you to do is define a module.modulemap for your library:
module StaticA {
header "StaticA-Swift.h"
}
Typically StaticA-Swift.h isn't available and won't be generated, you "might" be able to get away with not specifying it ... but I've not had any luck and have needed to do it manually.
You can use a script which will copy the generated *-Swift.h to the include folder so that you are able to reference it from your modulemap file.
#!/usr/bin/env sh
target_dir=${BUILT_PRODUCTS_DIR}/include/${PRODUCT_MODULE_NAME}/
# Ensure the target include path exists
mkdir -p "${target_dir}"
# Copy any file that looks like a Swift generated header to the include path
cp "${DERIVED_SOURCES_DIR}/"*-Swift.h "${target_dir}"
Go to your Project's Build Phases
and
Click on the "+" under "Link Binary With Libraries" to add a new library. Then click on the "Add Other" button.
and pls also ensure you have the lib path to Library Search Paths under Build Settings
Hi guys I'm having a bit of trouble creating a static library in xcode 5. Most of the tutorials out there are done in xcode 4 and thanks to apples incredibly easy to use gui, that makes it so easy for users to transition from one program to another, so I haven't been able to make one and use it.
So I get that the first step is to make the cocoa ios static library project and then to add the header and implementation files (.h and .m) that you want in your library.
Next you supposed to set the header files that you want to be accessible by the user. Is it possible to set up the library in such a way that importing one header file also imports all of the other header files? Do the other header files need to be public to do this?
My main problem is how do I actually set the classes which I want to be public/private and finally how do I implement this library into one of my applications?
A HelloWorldLibrary example would be great!
After using the link: github.com/jverkoey/iOS-Framework
I am now having a problem with the locating of the Framework:
ld: warning: directory not found for option '-L/Users/Harry/Library/Developer/Xcode/DerivedData/SampleFramework-efznryzmlxnimoaaazjfbqjirzxq/Build/Products/Debug-iphoneos'
ld: framework not found SampleSubproject
There are steps to create static library.
I have not created in xCode 5, but have created in 4.x..
Create new project and select Cocoa touch static library under iOS.
Add Class files/Resources to your created project.
Set Installation Build Products Location to $(BUILT_PRODUCTS_DIR)
Copy headers in Build Phases
Set headers to Public in Target Membership
Build for Archiving/Profiling
got it from derived data (Release iphonesimulator, Release-iphoneos)
now merge both .a files using
lipo command from terminal like lipo -create libForDevice.a
libForSimulator.a -output UniversalLib.a
Now copy this lib to your main xCode project and include your perticular class.
You can find more details from here
Regards.
I have added a framework to xcode project. Under Build phases->Link Binary With Libraries.
The framework consists of a library file (.a file) and a folder "Headers" which includes all the necessary header files for that framework.
Now I am trying to import a header file in the framework to one of my classes.
#import <MySDK/MyHeaderFile.h>
But an error occurs "Symbol not found" while building.
My understanding was that, if we are using framework instead of library file there is no need to add the header files path in "Header Search Path".
But still, I have specified the path to my framework in header search path.
Also I have specified the framework path in Framework search and Library Search path options.
This is first time I am working with frameworks. For libraries I just added the .a files and specified full path to header files in header search path.
What configuration am I missing for adding frameworks?
If it's a static library file and a bunch of headers, it's not a framework. A framework is a specific method of packaging files. On MacOS X static and dynamic frameworks have one structure, while static frameworks on iOS have a different structure.
For a static framework using Xcode 5, your file structure would look like this:
MySDK.framework/
en.lproj/
Headers/
MyHeaderFile.h
Info.plist
MySDK
Where MySDK is the binary archive file (it should not be MySDK.a). If you have a file ending in .a , you have a static library rather than a framework. Building a static framework using Xcode 5 isn't easy but it is also not impossible. Building a static library is much, much easier and trouble free however. It sounds like you already have a static library, so you just have to tell Xcode where to find the library archive and header files using the appropriate search path settings for your project or target.
If/when you DO have a framework, adding it to "Link libraries and frameworks" OR setting "Other linker flags" to "-framework path/to/MySDK.framework" will work fine.
Newer versions of Xcode may support different functionality for building or using frameworks, however linking against them should be largely the same.
MySDK/MyHeaderFile.h : This explains that your library is inside MySDK folder. Check if it exists in same path. Otherwise you'll get "Symbol Not Found" error.
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.