I am creating a static library for my project. Is all the classes created inside static library has to copy files in build phases? I have added only some of the files in build phase ->copy files. Now i am using this static library in my project. I got file not found error in static class file.
For Example:
Static Library - > It has 2 Classes.
1. One.h One.m
2. Two.h Two.m
In Two.h header file it has #import "One.h"
In build phase-> Copy files added only Two.h(As i don't want to show One.h to everyone)
MYProject - >
I am using Static library in this project.
I have added StaticLibrary.a file and the header paths.
Now i imported Two.h in my Project.
#import <StaticLibrary/Two.h>
Error:Cannot find the class One.h -> Inside Two.h
Could anyone help me to resolve this issue?
Even if you have a static library, if you don't have the "One.h" file then the other headers can't have it as an import.
Sorry, but you'll have to show One.h to everyone, or else rearrange your code. What is it that you don't want to expose? Does it have to go into a header file?
Related
Hi i want create one Common SDK for 3 Project which have same functionality in it but for creating that SDK we need to use some of the pod and bridging header file
we faced issue with how to configure that SDK with pod and bridging header which is used in all 3 apps to work on
Please help me how can we achieve this.
i have tried to add pod with bridging header but some how pod and bridging header not working
You can create framework project with pods and third-party library.
Note: You can't use bridging headers within a framework.
There are 2 Solution.
1. umbrella header
2. module map
Solution 1 (umbrella header):
To include the required Obj-C header you need to set it as Public: select it in the project explorer (left pane) and change the property Target Membership (left—Inspectors—pane) from Project to Public.
[Target Membership Public]
https://i.stack.imgur.com/P26rx.png
Open umbrella header (.h) and import the required header as:
[Import Headers in umbrella header]
https://i.stack.imgur.com/WEsLG.png)
This effectively makes this header public and available to both your own framework and anyone who uses it.
Note: If you import the header as a local file, i.e. in quotes, e.g. #import "objc-header.h", you likely to hit the compiler error telling you are trying to include a non-modular header.
Solution 2 (module map):
Create a file named module.modulemap in the root of your project with the following contents:
[module.modulemap]
framework module FrameworkName {
umbrella header "FrameworkName.h"
header "objc-header.h"
export *
module * { export * }
}
In case you want to keep the definitions from objc-header.h private from the users of your framework you can add private qualifier like so:
// ...
private header "objc-header.h"
// ...
In Build Setting set Module Map File to module.modulemap
Clean the build directory (⇧⌘K) and build the project (⌘B)
In a sample app that I have created, have used the openssl lib using module map.
Following is the structure of module.modulemap file.
framework module TestApp {
umbrella header "TestApp.h"
export *
module * { export * }
header "opensslv.h"
header "x509.h"
header "pkcs12.h"
header "pem.h"
}
Apart from that, I have also added include & lib folders to my project.
This approach works perfectly fine for the sample swift app. Source code compiles and the openssl apis are exposed to swift.
Now comes the actual question. When I am creating a swift framework and following the above process of creating module map & adding include & lib folder to the project structure.
I get an error on this line of "pkcs12.h".
include <openssl/bio.h>
'openssl/bio.h' file not found'
I have added the Import paths, Header Search Paths in build settings.
As the OpenSSL is C based library, It does not compile for the swift framework.
The bridging header is also not working for the swift framework.
Can someone help me here or understand the better way to include the OpenSSL library for swift framework?
https://drive.google.com/file/d/1B4NFbTQG0JjSkZgFx0yy1jYw-lRxX1Oa/view?usp=sharing
I have added the sample project link. In TODO section, I want to use the OpenSSL methods.
Note: I was able compile the openSSL lib using the below script.
sed -E -i '' 's/#[[:space:]]*include <openssl\/(.*).h>/#include \"\1\.h"/'
$SCRIPT_DIR/../Libraries/openssl/include/openssl/*.h
I fixed the compilation issue and was able to access the OpenSSL API's.
I had to make a few changes to the module map file.
//
// module.modulemap
// NiksWay
//
// Created by Suraj Gaikwad on 14/03/22.
//
framework module NiksWay {
umbrella header "NiksWay.h"
export *
module * { export * }
explicit module OpenSSL {
header "pkcs12.h"
header "pem.h"
header "opensslv.h"
header "err.h"
link "libcrypto"
link "openssl"
export *
}
}
I have a project that requires a local framework.
The project has the frameworks set up in a frameworks folder.
The new local framework is placed in it as well. The result folder structure is like that:
project
-- frameworks
---- theFramework.framework
------Headers
--------TheFramework.h
--------file1.h
--------file2.h
--------subfolder
----------Subfolder.h
----------Another.h
In the Bridging header the TheFramework.h and the Subfolder.h need to be imported.
It looks like that:
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import <TheFramework/TheFramework.h> //This one is working just fine
#import <subfolder/Subfolder.h> //This one fails with File not found
#endif /* Bridging_Header_h */
If I change #import <subfolder/Subfolder.h> to #import <TheFramework/subfolder/Subfolder.h> then it seems that the file is found because then it fails in Subfolder.h where it tries to do #import <subfolder/Another.h> and fails again with a Not found
If I change subfolder/Another.h to TheFramework/subfolder/Another.h then it works here as well.
Now in my real life scenario I have 4 header files in different subfolders all importing around 50 other files so changing all of the imports will be... annoying.
Also if later we want to update to a newer version of the framework, all the changed imports will be lost.
Does someone know how I can solve that issue? Either by having the project find the imports as already defined or by for example defining a value somewhere that makes the compiler understand that subfolder/file.h equals to TheFramework/subfolder/file.h ?
Thank you!
Found the solution I had to add
"$(SRCROOT)/frameworks/theFramework.framework/Headers"
to my targets User Header Search Paths (Target -> Build Settings -> User header search paths.
This seems to let the compiler know where additionally search for header files including subfolders.
I am trying to create a Cocoa Framework from XMPPFramework (which, despite its name is not a Framework, but just a bunch of files).
I am doing this because the XMPPFramework project contains a lot of moving parts (copied source files from other projects, optional source files, weird includes) and we are trying to abstract this away from our main project and include it using Carthage like any other framework.
It almost works. I could include all the files, bundle it into a Framework in Xcode and build it with Carthage. There remains one only problem. Some public .h files contain funny includes like:
#if !(TARGET_IPHONE_SIMULATOR)
#import libxml;
#else
#import libxmlSimu;
#endif
With a custom modulemap:
module libxml [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h"
export *
}
module libxmlSimu [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/libxml2/libxml/tree.h"
export *
}
module dnssd [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/dns_sd.h"
export *
}
module dnssdSimu [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/dns_sd.h"
export *
}
You can find the related commit here.
I added the path of the modulemap file in the Headers search path build settings of Xcode. Compilation of the framework works fine.
However, when I include this header in my main project, those custom modules are not found and compilation fails. This is because those custom modules are not exported and the main project does not see them.
I tried to create a custom modulemap file instead of having Xcode generating a generic one.
framework module XMPPFramework {
umbrella header "XMPPFramework.h"
export *
module * { export * }
}
module libxml [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h"
export *
}
module libxmlSimu [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/libxml2/libxml/tree.h"
export *
}
module dnssd [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/dns_sd.h"
export *
}
module dnssdSimu [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/dns_sd.h"
export *
}
And adding it to the Xcode config:
That's where I get into problems! It now seems that the custom modules are defined twice! Once by the XMPPFramework's modulemap file, and once by me.
Fine! I said. I'm just going to remove the modulemap path from the Header search path and it will solve it. Well, it does not... Now the custom modules cannot be found anymore:
To summarize:
I need to define the custom modules in my modulemap otherwise the main project does not see them and is unable to compile.
If I include the XMPPFramework's modulemap path in Header search path, I get a "duplicate module" error and it does not compile.
If I include my own modulemap path in Header search path, I also get the "duplicate module" error.
If I do not include a modulemap path in Header search path, the compiler does not see the modules and it does not compile.
How can I declare custom modules in my modulemap so that they are exported, and also use them while compiling the project?
If I'll run my app, this 3 errors comes up.
Does someone knows why?
Here is how I import GPUImage:
Step1 (added the GPUImage.xcodeproj file into my project):
Step2 (added the GPUImage Objects to "Target Dependencies"):
Step3 (added the libGPUImage.a file to "Link Binary With Libraries"):
Step4 (added in the Header Search Path the Source folder from GPUImage):
All in all I followed this tutorial:
You need to add this #import "CPUImagePicture.h" in your .m file