How to include a static library and have its #import paths still be valid? - objective-c

Say I have a static library that was created with the following file structure:
Folder1
File1.h
Folder2
File2.h
Now inside of File1.h, it refers to File2.h without a path (e.g. #import File2.h). The library builds successfully. (It doesn't require the full path (i.e. #import Folder2/File2.h) because both files are part of the same project.)
Now when I include this library in another project, that #import File2.h statement no longer compiles, and I have to change it to #import Folder2/File2.h (or something similar). This means that I have to modify the original library, which is not good.
The specific error message I get is:
File2.h: No such file or directory
There doesn't seem to be a way to let it know that both files should be a part of this new project, since the only two files I see after I included the library are MyLib.xcodeproj and lixMyLib.a.
The way I included the static library in my new project is by doing the following:
Drag MyLib.xcodeproj into my new project.
Add the libMyLib.a file to my new project's target.
Add to the Header Search Paths a relative path to the home directory of my library (the folder that contains Folder1 and Folder2).
Is there any way I can have it automatically know where to find these files just as it was able to do in the library itself? I realize that I can probably add the paths Folder1 and Folder2 to the Header Search Paths of my new project, but I'm looking for a better way, since these two folders are just an example, and it could just as easily be 50 folders I would need to include. I'm looking for a solution which doesn't require me to type the paths to all 50 of those folders, if possible.

Try checking the "Recursive" checkbox next to the path to the parent folder of all those headers.

Related

Xcode cannot find header files when files added in folder reference mode

I am trying to add many Objective-C files to my Swift project with folder reference mode that means when I drag and drop my files into project I am selecting "Create Folder Reference".
This is because all of my obj-c files use #include "/folder/folder/folder/" for example. These files are generated with j2objc project.
Now my problem is when I want to #import or #include some .h of these files in myproject-Bridging-Header.h Xcode can't find the header files.
I use #import "/folder/folder/folder/" like generated files but no chance.
I add $(PROJECT_DIR)/ in build settings - search header paths but it does need to write path completely like $(PROJECT_DIR)/folder/folder/folder/.
Is there any way to set main folder and Xcode find subfolders ? Or do I need to write every path separately ?
I found the answer after many days by myself!
When I drag and drop my files to my project in Xcode in mode "Create Folder Reference", just a reference to the files is added to Xcode and the files were in their folder where in my Mac.
I resolve this problem by add files to project's folder manually and then drag and drop from that location to Xcode. After that, I could access my file by its address in myproject-Bridging-Header.h like #import "/folder/folder/folder/file.h"

Configure CMake to show include directory in QT Creator

I'm trying to figure out how SFML's CMake configuration shows the <SFML/*> include directory in a project folder.
My test project has include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) but the include folder does not appear in the project structure like SFML's
The folder will show up if you have added any source files from within that directory (or a subdirectory below it) to any target in the project. Since you are talking about headers, you can simply add the header files as sources to an existing target. CMake will just ignore them as far as the building of that target is concerned, but it will then add those headers to the project's list of files. I've also seen people add a static library target with nothing but headers listed just so those headers show up in the project view. A bit hacky in my opinion, but it gets the job done.

Header file not found

I have a project, which has a static library with references to header files like this:
#import <libetpan/libetpan.h>
I can't change this import line. What should I do, to make Xcode find those header files? I have a folder with header files, that I can import to the project. Thanks.
At the moment the error is following:
'libetpan/libetpan.h' file not found
You may have added the libetpan folder to your project (if not, do so)
right click on that folder and see the path (get info after right click)
if its not a sibling of your project file in the folder structure (check in finder), thats where its going wrong
alternately, you could add header search paths: header search path in XCode 4

What should I do if I can't find the GPUImage.h header for the GPUImage framework?

I have created a sample application to perform bump distortion, using the GPUImage framework. I added this framework to my application, but I'm seeing the following error
Lexical or preprocessor issue 'GPUImage.h' file not found.
I have added the -ObjC flag to the Other Linker Flags, but I'm still seeing this error. How can I solve this problem and get my application to compile?
Adding GPUImage framework to XCode project could be tricky. So I haved added detailed step-by-step instructions w/ images on how to do it.
Static Compilation Method (detailed solution so we don't mess up)
This is Static compilation method. In this basically we will compile the framework using ./build.sh file. And simply add it to our XCode project, then configure XCode to properly use it.
Download GPUImage from Github and extract it (or just clone it).
Go to the GPUImagefolder in terminal
Run ./build.sh
Note: This will compile and create ready-to-use binary for all the sdks on your mac.
build.sh creates a folder called build and generates compiled binaries and dumps them to folders like: Release-iPhone, Release-iPhoneOS, Release-iphonesimulator etc folders.
For iPhone use Release-iphone (This also works for simulator).
Copy (not drag-drop) Release-iphone to your XCode project's root directory so that we have a local copy of framework.
Now iPhone drag-and-drop Release-iphone onto your XCode project. Make sure to check "Copy to .." option.
Note:
This Release-iphone folder contains two sub-folders: include and lib
include folder contains all the header .h files
lib folder contains compiled binary version file called libGPUImage.a
We now need to simply configure XCode to use .h and .a files.**
Select your project in the project explorer > Project name under Targets > select Build Phases > Expand Link Binary With Libraries
Add the libGPUImage.a to Link Binary With Libraries section. You may want to Right-click on libGPUImage.a then Open in Finder and finally drag-drop it.
While we are at it, also add the following GPUImage's dependent frameworks/ libraries
CoreMedia, CoreVideo, OpenGLES, AVFoundation, QuartzCore to Link Binary With Libraries section
Now, lets configure .h headers.
Select your project in the project explorer > Project name under Targets > select Build Settings > and type search paths to see search paths section.
Open Headers Search Paths by clicking on the value field.
Drag-and-drop the lib folder to that popup. Note: If it shows absolute path, change it to looks $(SRCROOT)/path/to/lib/. (You should have the framework relative to your xcode project see step 6).
Repeat 11 & 12 for Library Search Paths as well.
Additional tips: You can add .h files to Library Search Paths or Headers Search Paths, you can make them Recursive. I have a main root-folder called Dependencies folder where I keep all the dependencies like MySDK-framework including Release-iPhone. And I just have one search-path at the Dependencies (root folder) and made it recursive.
Did you follow all of the instructions from the Readme on the project page? From the installation instructions:
You'll also need to find the framework headers, so within your
project's build settings set the Header Search Paths to the relative
path from your application to the framework/ subdirectory within the
GPUImage source directory. Make this header search path recursive.
If you're seeing the above error, it means that you did not point the Header Search Paths at the right directory where you've installed GPUImage relative to your project, and / or did not click the checkbox to the left to make those search paths recursive.
I show some screenshots of where you need to go to set this in this answer, which explains something similar for the Core Plot framework. The same principles apply, only you need to find where you installed the GPUImage framework at.
I add relative path to "Header Search Paths", but there is still a error that is "not found".
Then, I add path to "User Header Search Paths", and it works.
May help you.
finally, I realized the KEY WORD is relativeļ¼
I put GPUImage source files in my project root dir:
before I solved the problem, I add Header Search Paths is:
$(PROJECT_DIR)/GPUImage/framework
$(PROJECT_DIR)/GPUImage/framework/iOS
and make them Recursive, but error is still there, So I changed Paths to:
GPUImage/framework and make it Recursive, then it works.
Hope it helps.

Xcode - how to include c library and header file to cocoa project?

How do I add c library to Xcode Cocoa project?
Or what is the best option, I don't want to copy them into Cocoa project directory.
I have a C project called a which compiles into library a.dylib and header file a.h, the project is located in it's own directory.
I want to use this library from my objective-c application in Xcode.
How do I add the header file and library to my Xcode project?
I can drag the a.dylib into other frameworks but what do I do with a.h?
I figured it out.
I point to location of project a deployment directory (headers) to Search Path in project settings either:
as Header Search Paths, if used as <a/a.h>
or into User Header Search Paths, if used as "a/a.h"
As for library I just drag it to Xcode project and set it to refer to library instead of copy.
Here are the steps before adding a header file test.h in your project. Here is the files location root -> Library -> include -> test.h
click on build settings
Find User Header Search path. add your header file location here. add following value to Debug, Release and Any Architecture field. $(SRCROOT)/Library/include. Your project Root is the folder that contains your project, it conatins .xcodeproj file.
After adding path you will be able to add header in like this
# include "test.h"
You can drag them both the .a and .h files to Xcode, but make sure to not check the "Copy items to project folder". As for referencing the header file, you'll need to put it in a place where you can add a path to it in your #include/#import statements. Is there a reason you don't want to copy the header to your project file?