File not found on Xcode9.3 - objective-c

I'm currently working on a project (single view application) in Swift on Xcode using a precompiled sdk (Parrot SDK3: http://developer.parrot.com/docs/SDK3/#ios).
My issue is that I have a "file not found" error whereas the file exist:
The headers I try to import are written in Objective-C (but I want to import these headers in a ObjC file).
I took care to write correctly the path to the header files and to avoid cyclic import. After a lot of clean/build and a lot of methods attempted I don't know what to do.

Xcode tries to find header files (.h) with a help of "search paths" list.
You can have multiple search paths in this list, for example if you have #import <a.h> in the program, and you have paths "/asd" and "/qwe" in your search path list, it will try to find the header as "/asd/a.h" or "/qwe/a.h" (it tries both).
You can add custom paths in Xcode project build settings. There's a section "Search Paths" and there you have "Header Search Paths". If your library is inside your project, then it is useful to use $(SRCPATH) variable in the path, which expands to your project root folder like so:
Note that if you import as <somelib/somefile.h>, and your path in "Header Search Paths" has something that ends with "include" like "/some_path/include", then the header must be at "/some_path/include/somelib/somefile.h", which is sometimes not true, because often people place header files right inside "include/", not inside "include/somelib/".
One way to solve this would be to make a symlink that points to the library "include" folder, with your custom name, and then add a parent directory of that symlink to your header paths.
For example, if you create an empty directory "libs/include/", and you have put your library files at "libs/dist/libARDiscovery/.../include", then you can create a symlink "libs/include/libARDiscovery" that points to "lib/dist/libARDiscovery/.../include", and then add "$(SRCROOT)/libs/include" to the header search paths.

Related

How do I include MTL_HEADER_SEARCH_PATHS in Swift Package Manager Package.swift?

In a internal .metal file in the ShaderPackage defined in Package.swift, I want to include an internal header. That header is nested deeply inside the include folder and I don't want to have to use the relative path. In a non Swift Package Manager (SPM) project, I can just set MTL_HEADER_SEARCH_PATHS to recursively include all subfolders, then include Header.h anywhere in the project without needing to know exactly where it is. (This isn't about exposing either file beyond the package bounds - just an internal-to-package question).
First question: Is there a way to set MTL_HEADER_SEARCH_PATHS from a Package.swift (manifest file for SPM)? Doesn't look like there's any build settings for Metal, only C, CXX, and Swift. Whatever settings I add to cSettings in the form of .headerSearchPath("include/subfolder") doesn't get picked up by Metal, nor .cXXSettings or .swiftSettings. Can I define a custom setting somehow?
Second: If there's a way to set MTL_HEADER_SEARCH_PATHS, can I do it recursively? Or do I have to add each subfolder within include? Thanks!

How to add Objective-C Bridging Header entry?

I have a Swift project and have add a cocoapod, which is written in Objective-C. It has header and implementation files. From what I understand, to use/import these files into my Swift files, I need to add a bridging file.
I found this site describing how to do this manually, since the Objective-C files are already part of my project (from the cocoapod).
http://www.learnswiftonline.com/getting-started/adding-swift-bridging-header/
1.) Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. You may find it faster to type in “Swift Compiler” into the search box to narrow down the results.
2.) Next to “Objective-C Bridging Header” you will need to add the name/path of your header file. If your file resides in your project’s root folder simply put the name of the header file there.
I don't have a Objective-C Bridging Header in that section and it doesn't appear you can add new entries there.
I'm using Xcode 7.3.1. Anyone have some idea how this should be done?
Are you sure you looked at the correct Build Settings section, search with the keyword Swift compiler - General in the search field as describe below and then you can find it.
You need to create the header file first. It is a regular Objective-C header file and should be named <Your app or framework name>-Bridging-Header.h. For any Objective-C headers you want Swift to know about add an import statement to the newly created header file. Then follow your previous steps.
There is also a hidden header that gets created for you called <Your app or framework name>-Swift.h. If you need to access any Swift classes from an Objective-C file import this header.

Xcode - Use header imports with folder-based paths

I'm using a static library and pointing Xcode to a folder with the headers in it. These headers are organized in a hierarchical folder structure:
headers:
- a.h
- b.h
- subheaders:
- c.h
- moreheaders:
- d.h
I also have some prewritten source code that uses this library, and it refers to the headers based on their locations: #import "subheaders/c.h".
However Xcode flattens the folder hierarchy, forcing me to use #import "c.h". There's a good deal of code, and I can't rewrite it very easily to stop using the foldered imports. Any way to make Xcode recognize the folder structure?
P.S. I'm including these headers using the "Library Search Paths" "Header Search Paths" build setting under my primary Target. The search is non-recursive, so I don't know how it even finds the nested headers...
Thanks for your help!
Xcode builds header maps by default and header maps are flat, except from modules/frameworks, where the map is ModuleName/Header.h. For details about how Xcode builds these maps, which settings exist and what the compiler does, if a file is not found in a map, please see this answer.
Setting an appropriate header search path (HEADER_SEARCH_PATHS or USER_HEADER_SEARCH_PATHS) will make path includes possible, regardless if header maps are used or not, yet the flattened import will still work as well in that case. If you don't want the flattened import to work, you need to disable header maps or ensure that the header files in question are not added to the maps, as shown in the other answer.
Unfortunately this was just a case of my not being observant. I had added the headers to the search path, but I had also earlier added them as source to the project (to see if I could get it to work that way). When I removed the source folder and kept the header search path I could reference files by their full paths. Thanks for the help.
after Hours of try and fail i found an option in XCode 9.4.1 in an XCode 9.3-compatible project the option to disable the usage of
Ues Header maps
This will let Xcode recognize the project structure.
i althought set every file and folders location to be project relative
I Hope there is someone with the same problem and has now an solution

import "cocos2d.h" works in some files, but not all

Here is what I did:
In Xcode 4.3.1
File -> New -> Project -> Single view application
Dragged the file cocos2d-ios.xcodeproj into navigator.
In build phases settings : Added : libcocos2d.a (becomes highlighted in red), as a linked library (required).
Added OpenGles.framework, Quartzcore, and libz.dylib
Changed build settings - Set "Always Search User Paths" to YES
Added cocos2d source directory to "User Header Search Paths"
Now, it seems I can type: import "cocos2d.h" , in the app delegate and root view controller that Xcode created. But if I create a new file, and I add the line "import "cocos2d.h"" to the top, Xcode complains that the file is not found. But it seems to build fine. Also, in this new file code sense does not work.
What should I do? Why can I import only in the files that Xcode created? Is there some setting I need to change so that in the files I create, I can import cocos2d ?
EDIT: It seems to build and run fine. I can call methods in the cocos2d api. code sense just doesn't seem to see cocos2d.h in the new files I create.
EDIT - it seems that code sense suggests cocos2d.h when i type : import "
But it does not suggest classes / methods from the cocos2d api.
Turns out I had only added the "user header search paths" to my target, but not in the project settings.
Adding it fixed the problem. I guess the reason it compiled fine was because I had added it to the target, but it didn't work in the text editor since I hadn't added it to the project.
This happened to me as well, even though I did add it to both project and target.
However, what worked for me was to select the RECURSIVE checkbox under "User Header Search Prefixes" (which was set to "/lib/**")
I had same issue.
My project -> Build Settings
Look for the entry for Search Paths
Always Search User Paths - YES
User Header Search paths - "myProjectName/libs" //I put box2d folder here
Hope this help someone.

Include issue: header file not found in iOS project in Xcode 4

Consider my setup looks like this:
XCode 4 iphone/ipad project
ObjC .m file that includes a new header file, this header is reported as "file not found"
ObjC .m file is located in root folder of the project
new header file is also located in root folder of the project
new header file was created within Xcode 4 as "C header file" (!!)
I tried using #import and #include statements with both "" and <> lookup syntax.
The project already consists of a bunch of other objC headers/classes and they work nicely. I suspect that creating the file as a C-style header is the issue.
I did explicitly NOT try to add a USER_PATH or anything like that, since it's all happening in the root project folder.
Any ideas? I'm really surprised how complicated such simple things can get!
! Additional comment: (EDIT)
I now verified that I can create any type of header (menu "new file"->"C/C++"->"header") and it will never be found by objective-C code. Even a new clean project behaves the same! What kind of feature is this?
Weirdness.
I talked to a bunch of fellow Xcode sufferers and they confirmed I HAVE to set the extra path variable. Their explanation was a bit odd though: in objectiveC the lookup (import) simply scans the whole subfolder structure, whereas an 'include' does not. From my point of view this would only be a valid argument if the header file in question was located in a subfolder! But mine is in the exact same location as the '.m' file!