xcodebuild cannot find header in embedded projects - xcode

I have a project embed another project, and the xcode GUI build was successful, but in command line xcodebuild failed as such.
fatal error: 'OHAttributedLabel/OHAttributedLabel.h' file not found
#import <OHAttributedLabel/OHAttributedLabel.h>
^
1 error generated.
but I had this in the project HEADER SEARCH PATH (where the h is located)
${PROJECT_DIR}/MyProject/Vendor/OHAttributedLabel/Source
the problem is the header is located in the "OHAttributedLabel/Source" folder, while the import statement is looking for header under OHAttributedLabel folder, I don't want to touch the embedded project directory structure, what can I do in this case?

The best way is to modify the embedded project to publish the header files:
Select the embedded project in xCode
Select the applicable target.
Click on the build phases
Expand "Copy Headers" section and add OHAttributedLabel.h file.
Select your main project
Select the applicable target.
Click on build phases.
Click on Target dependencies.
Make sure that the embedded project is added as a dependency.
Try to run the app
If the above doesn't work double-check the order of the build phases. E.g. make sure that the "Target Dependencies" build phase is before "Compile sources".

Related

Automatically add files other than source files to 'Compile Sources' build phase in Xcode 5

I have a custom build rule for a file type, which I setup according to this blog post. The build rule is working fine and my file is compiled.
But if I add a new file of this type to the project and I select the targets, the file is currently added to the "Copy Bundle Resources" phase. Instead, I'd like to have it added to the "Compile Sources" phase automatically (if I don't do this, the build rule won't kick in).
Is there a flag or something I can set so Xcode recognizes my files as "source files"?

XCode - Changes to static libraries doesn't cause the build system to relink the executable

I have a project "blackjack" containing a project (as a child) called "GameLib", which in turn contains many projects such as "Core-iOS". I have libCore-iOS.a added to "Link Binary With Libraries," but changing a .cpp/.mm file in the static libraries doesn't cause the executable to be linked against the new .a file. The .a file is being compiled with the changes. Why is the build system broken, and how do I fix it?
You need to configure all of your targets' dependencies.
blackjack
libCore-iOS.a << dependency
If Xcode's automatic dependency detection fails, then configure libCore-iOS target as a dependency explicitly. That then solves it.
If you have found automatic dependency detection in error, please consider submitting a bug report with projects attached. I have found errors in it, but was unable (erm.. unwilling) to submit projects for them to debug the issue.
To define an Explicit Dependency:
Open the "blackjack" Project in Xcode
Select the "blackjack" Project in the Project Navigator (Top-Level)
Select the "blackjack" Target
Choose "Build Phases" tab
Click '+' in "Target Dependencies" phase, and add libGameLib target as a dependency
Click '+' in "Link Binary With Libraries" phase, and add libGameLib
Now disable "Find Implicit Dependencies" in all schemes
Restart Xcode
Clean and Build Project
That should be all that's needed to create an explicit dependency, unless you have made some atypical mods to your build settings.

Is it OK to remove Prefix.pch file from the Xcode project?

The Xcode project generates Prefix.pch file automatically. When I deleted this file and tried to build, I got build error saying '*_Prefix.pch' file is missing.
Is Prefix.pch file is a must for compiling with Xcode?
How can I build without the Prefix.pch file?
In Xcode, go to your target's build settings (Command-Option-E, build tab) and uncheck Precompile Prefix Header (GCC_PRECOMPILE_PREFIX_HEADER). You can also remove the value of the Prefix Header setting if you wish.
Prefix headers are compiled and stored in a cache, and then automatically included in every file during compilation. This can speed up compilation, and lets you include a file without adding an import statement to every file using it. They are not required, and actually slow compilation whenever you change them.
Yes, you can compile and run the project without .pch file. In Xcode, go to your target's build settings (Command-Option-E, build tab) and uncheck Precompile Prefix Header (GCC_PRECOMPILE_PREFIX_HEADER). You can also remove the value of the Prefix Header setting if u want.

Xcode - duplicate Target - new Target fails to build

using Xcode 3.2.5 on 10.6.6 (10J521) and now 10J537.
I have an Xcode project containing 1 Target: "MyApp". It builds and runs successfully.
As well as source and resource files, the Target contains a "Copy Files" build phase which copies "Sparkle.framework" in. The framework is in the same directory as the project.
I want to duplicate this Target. Steps taken:
Did "Clean all Targets".
Right-clicked on the "MyApp" Target within Xcode, and then chose "Duplicate".
Renamed the duplicated target to "MyAppTarget2".
Selected "MyAppTarget2" as the Active Target from the popup menu in the top-left.
Did "Build".
The problem:
error: Sparkle/Sparkle.h: No such file or directory
At the line:
#import <Sparkle/Sparkle.h> // In MyAppDelegate.mm
This is puzzling! Further info:
Each Build step appears to have been replicated in the duplicated Target, including the "Copy Files" phase.
The Sparkle.framework itself exists in the project's folder.
In the "Link Binaries with Library" phase of both "MyApp" and "MyAppTarget2", I am linking to the Sparkle.framework at the above location. A "Get Info" on the linked binary reports that it is a member of both Targets.
If I right-click on the Sparkle.framework file within the "Copy Files" build phase of the duplicated Target, and select "Reveal in Finder", then the correct Sparkle.framework file is shown. The required file exists at Sparkle.framework/Headers/Sparkle.h
If I switch back to the original "MyApp" target, it builds and runs successfully.
Am I doing something obviously wrong here? Thanks.
[EDIT - SOLVED]
I had a look at the Build settings for each supposedly-identical Target.
Under "Framework Search Paths", the first Target had this:
$(inherited) "$(SRCROOT)"
But the duplicated Target had this path:
$(inherited) \"$(SRCROOT)\"
It appears that Xcode incorrectly escaped the path during the duplication process. Ouch.
I know you have already solved this issue yourself, but I thought I'd share my fix for this issue (as it has happened to me several times). I've always been able to get rid of this error by deleting the file in question and just recreating it. I have no idea why this works... but, as is often the case with XCode, there seems to be some Voodoo at work.
Build Phase copy is still broken in 12.5! It does only copy a few of the source targets build phases. What a crap IDE.

XCode 3.1.2, header file not found

I have been trying to build a code that has dependencies with other header files that are not in the project directory. I added the paths to these header files in both HEADER_PATH and USER_PATH. However, I still see error while building. It says that the file is not found. I verified that the file exist in the path added to the header search path in project settings.
How do I make sure that all my header files referenced in the project is included and the paths are being picked by Xcode during compilation?
I tried copying all the files to the project with no luck. This is the first time iam using Xcode, so its kind of frustrating. Iam a linux guy and comfortable with make files. Is there a Make file for xcode which i can modify to include the header file directories.
You might want to check the order of your source files in your target's build phases to ensure that your dependencies are compiled before your source files that reference them.
Select your project in the Project Navigator.
Select your target.
Click on the Build Phases tab.
Click on Compile Sources to expand the section.
Drag the dependencies to the top of the list.
Are you sure you spelled the header file name correctly ? Is the case correct ? Did you use user quotes "" rather than system quotes <> ?
Assuming you've checked all the obvious things such as the above then one other thing to try is to quit Xcode, delete the "build" folder in your project directory, and try again - sometimes the build folder gets in a pickle internally.

Resources