Xcode add header search path

Using XCode9, I have created a C-command line project and added an open source framework (gstreamer) in adddition to the corefoundation framework to my project.


The C-program uses the header files from gstreamer which are not found by the compiler causing an error. I cannot see where I can add the header path to my project. I have checked the Framework and Xcode lists in the Header directory all header files.


The following line causes the compiler error:

#include <gst/gst.h>


Asking for advice.

g

Michael

Replies

The first thing you should try is to use quotes to include the header file instead of angle brackets.


#include "gst/gst.h"


Angle brackets are for system headers. I'm not familiar with gstreamer, but there's a good chance the gstreamer headers are not system headers so Xcode isn't finding them.


If that doesn't solve the problem, you have to add the path to the gstreamer headers to either the Header Search Paths or User Header Search Paths build setting in Xcode. Select your project from the project navigator on the left side of the project window to open the project editor. Select either the project or the target from the left side of the project editor. Click the Build Settings button at the top of the project editor to access your build settings. There's a Search Paths collection of build settings, which contains the Header Search Paths and User Header Search Paths build settings.

And just FYI...I recently discovered that the path for some of my files were changed in the latest verison of Xcode to a subdirectory with /cnncncncn/ in it. The full path that needs to be inserted for your gst.h file in the User Header Search Path under Search Paths will be shown on the right in the utilities area when you select gst.h on the left.

The best way in Xcode to do this is: (using your example)

  1. Open Preferences
  2. Click "Locations" then the "Custom Paths" tab
  3. Click the "+" sign at the bottom left
  4. enter "gst" as the "Name" (no quotes)
  5. enter "GST Headers" as the "Display Name" (no quotes)
  6. enter the path name* to your gst folder as the "Path"
  • In the Finder, right-click / option click / two-finger click the "GST" folder, then hold the option and you will see "Copy" change to "Copy GST as Pathname". Do that and use paste it in for step 6

Ok no you have the first part. You created an Xcode system variable. The next part is to reference the Xcode variable in your project build settings by:

  1. Open the project
  2. Click on the folder button under the window close button
  3. Click on the blue project button/icon under the folder button
  4. In the column that appears to the right, click on another blue project button/icon
  5. In the row of tabs/buttons slightly higher and to the right, click on the "Build Settings" button/tab
  6. in the "Filter" text entry slightly lower than the tabs to the far right, enter "Search" without quotes
  7. below you should see "Search Paths" with a chevron, click the chevron if it is pointed at the word "Search" and it opens up the options
  8. below "Search Paths" you should see "System Header Search Paths". again click the chevron if it is pointed at the word "Search" and it opens up the options
  9. Hover over the word "Debug" below "System Header Search Paths" and a grey "+" button thing will show to the right, click the "+" button
  10. "Any Architecture/Any SDK" will appear and your cursor will be in a text entry. Type "$gst" without quotes
  11. Hover over the word "Release" below "Debug" and a grey "+" button thing will show to the right, click the "+" button
  12. "Any Architecture/Any SDK" will appear and your cursor will be in a text entry. Type "$gst" without quotes

Now you should be able to put...

#include <gst/gst.h>

or maybe

#include <gst.h>

... in your code and have it compile.

Unfortunately Xcode has some problems with the basics of what an IDE should do so you may have to fiddle with the pathname vs what you put between the <>. Be aware that you also may need to close all projects and quit between edits of the "System Header Search Paths" and the "Custom Paths" to get Xcode to recognize changes. You may also have to delete the "Custom Paths" and re-enter it to get Xcode to recognize changes.

<sarcasm mode> Isn't that easier than it was in 1991 with drag and drop of a folder into "system headers" and "project headers" in CodeWarrior and MPW? </sarcasm mode>

Small update.

In making this work, you may find it valuable to open the project bundle (directory, not a file) in BBEdit, then open the project.pbxproj inside and look for where Xcode is putting the reference to your "Custom Location".

My custom location is named $C0re so it is easy to find.

I found it very handy to be able to delete any line with the Custom Location generated into it by Xcode to force Xcode to update and to clean up the GUI mistakes in generating the lines in the project.pbxproj file.

There is some kind of caching going on and you may not see the change you apply via Xcode to the "System Header Search Paths" in the actual file showing simultaneously in BBEdit until you command-s the project files in Xcode. You would think that quitting Xcode would commit the changes to the project file but it did not seem to do so sometimes. (Xcode's caching system is problematic at best)

It took a couple of hours but now I am able to use

#include <C0re/C0reTypes.h>

in my project. Again so glad we advanced past that primitive old drag and drop thing 🙄