Xcode 4.2: How to Import .H File from Subproject

Xcode 4.2: How to import .h file from subproject

Maybe your header file is also in a subdirectory.

Imagine the following directory setup:

- Desktop
- MyProject
- MyProject.xcodeproj
- main.m

- MyLibrary
- MyLibrary.xcodeproj
- MyHeaderFile.h <-- wanted header file

If main.m has these contents:

#include "MyHeaderFile.h"

int main() {
return 0;
}

The compiler (gcc) will think that MyHeaderFile.h is located in the same directory as main.m, from which it is included. To tell the compiler you mean the header file in a subfolder, you have can do two things.

  • You can add a directory to the gcc compiler that says: "hey, also look in that folder". You can do this by using the -iquote myFolder flag.
  • You can include the directory in the include-statement: #include "MyLibrary/MyHeaderFile.h"

There could of course be another problem, but this seams like the most straightforward one.

How to access subprojects header file in main project

You will need to add the path of the sub project to the search path for headers in the main project, for reading how to do it check this Adding system header search path to Xcode

Import XCode project inside another XCode project

Try adding the location of your other project to the Header Search Paths in the Build Settings of the main project.

two projects in xcode4 workspaces (#import failure)

You can add the header or source folder of your project you're referencing to your Header Search Paths.

  1. Click on the target that's importing JSONRequest.h.
  2. Click on Build Settings.
  3. Enter "Header Search Paths" into the search box.
  4. Double click on the value cell.
  5. Click the + sign.
  6. Set the path to the project you're referring. Let's say it's called JSONlib. The path is relative to the root of the referring project (the project that's using JSONlib). For example: ../JSONlib/src/headers/ or wherever it is that the .h file lives.
  7. Click done.
  8. Clean and then build.

You'll find more info about this problem in the apple developer forums. Best of luck.

Xcode 4.2 how include one project into another one?

This makes a lot of sense when you are trying to add a static library to your xcode projects. There are a couple steps required for doing this. First, make sure that the static library project is not open in XCode.

Then start by dragging and dropping the static library xcodeproj file (from the Finder) onto your app's xcode project.
StaticLib

After this you need to add this library to your app's build phases. Click on the main project, and select the BuildPhases tab of the target.

Build Phases

You're going to want to add the other project to the Target Dependencies and to your Link Binary With Libraries Section.

Finally, the app needs to be aware of your headers. Therefore, you need to add the path to your static libraries classes to your User Header Search Paths. Go to the Build Settings of the Main Target and search for Header Search Path.

Header Search Path

This will make your app aware of the new static library.

Sometimes you need to add a few Other Linker Flags. In the Build Settings search for Other Linker Flags and add -all_load and -ObjC

Other Linker Flags

Hope this helps, I know the first time I tried to do this I was banging my head against the wall for a while.

How to set Header Search Path according to .h and .m

  1. Copy SpeechToText Project and put it inside folder containing Speech2ooText project.

  2. Now Drag and drop this (SpeechToText) project inside Speech2ooText Project.

  3. Go to Build Settings of Speech2ooText--> Header Search Paths and add this path

    ${SRCROOT}/3rd Party

    ${SRCROOT} --> it is the path to your main project (Speech2ooText in your case) and by

    giving '/3rd Party' we are telling headers are inside this folder.

Compile, Build or Archive problems with Xcode 4 (and dependencies)

NB: The steps below will solve 90% of your Xcode archive issues
however, from the comments it is suggested you try quitting Xcode
first. This may save you hours of setting tweaking.

  1. Check the "user header paths" are correct (Add "" to paths for spaces, both in your project and dependencies)
  2. Set "Always search user paths" to YES
  3. Create a group call "Indexing headers" in your project and drag the headers to this group, DO NOT add to any targets when prompted. This includes any headers inside your .xcdatamodeld, you'll need to right-click and view package contents to find them.
  4. For all dependencies set "Skip Install" build setting to "Yes"
  5. Moving any "Public" headers in Build Phases to "Project"
  6. Set the Build Setting "Installation Directory" on your Target to $(LOCAL_APPS_DIR)
  7. Change the target build setting "scan all source files for includes" to YES. (link)
  8. With newer versions of Xcode (> 4.2) you might want to read this question related to workspaces.
  9. Manually delete the project.xcworkspace files form all referenced projects


Related Topics



Leave a reply



Submit