Thomas Clayson
Thomas Clayson

Reputation: 29925

Two targets, two header files with the same name how to use each header for the right target?

Ok, here's what I've tried.

I have the header files in two separate directories IRL. They're named the same, but are in two different locations.

I want to only include the relevant header file for each target. Lets say for ease of explaination that the header file is called "Config.h".

So I have:

${PRODUCT_DIR}/Header1/Config.h

and

${PRODUCT_DIR}/Header2/Config.h

These files appear in the LHS of Xcode as well in two different groups (Header1 and Header2 which point to the IRL folders).

So now all I need to do is to make Xcode choose the right one from the right folder for each target.

Target1

and

Target2

I have tried adding the path to the User Header Search Paths for each target, but its still choosing the wrong one. I've also tried toggling "Always search user paths" which also doesn't seem to have an effect.

So my question is, is this because they're in the Project directory? Or is it because they're in Xcode in the file manager on the LHS, so therefore Xcode is copying them into the build folder?

The strange thing is it seems to be choosing the header files from the folder with the last name alphabetically...

In previous versions of Xcode I'm sure you could choose which headers to copy into the build folder.

Anyway.. does anyone know how I can fix this so that I can have it select the proper header file for the target?

Many thanks.

Upvotes: 13

Views: 3739

Answers (2)

Jose Pose S
Jose Pose S

Reputation: 1295

I have 4 targets in 1 proyect and more than 40 headers, the best solution in XCode 8 I think the best solution is change the following tag:

Always Search user Paths

To yes an all was fine for me: enter image description here

Upvotes: 1

Thomas Clayson
Thomas Clayson

Reputation: 29925

The problem I was having was 2 fold:

  1. You need to remove the header files from the project. If they're in Xcode, in the file manager, then they will automatically be included in the project.

  2. You need to use relative paths to your folders in "User Header Search Paths". I was using ${PROJECT_DIR}/path/to/header/folder which gave the right path, but didn't seem to work properly. Changing the entry to ./path/to/header/folder instead worked fine.

Upvotes: 9

Related Questions