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

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.

Related

xcodebuild cannot find header in embedded projects

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".

Deleted .pch file by mistake

I have deleted my .pch file by mistake, and now my project cannot be built anymore.
What should I do?
I take it you don't have version control?
You could just use the contents of a pch file from a different project or create a new one. If you search in your build settings for "pch" you'll see what the name of this pch file is expected to be and where it should be in your project

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.

How to unconditionally copy headers in Xcode?

I have set a header file's role in Xcode to private so that it will get copied to the desired location by the Copy Headers build phase. It works as expected if there is not already a header file of that name in the target location. But if there is an existing file, it does not overwrite it. Even if the header file has changed in the project it doesn't seem to update the copy in the target location. The Build Results windows shows a line "Copying MyFile.h" but the file is the old one.
This doesn't seem right and is definitely not what I want. How can I force Xcode to unconditionally copy (and overwrite if necessary) header files in the Copy Headers build phase?
Are you sure that you have actually changed the header file in the project? If Xcode says "Copying MyFile.h", then it's copying it. But if you accidentally changed the copy, instead of the original, then Xcode is simply doing what it thinks is right: copying the authentic version from the project over the altered version in the build product.
It would help if you'd paste the entire "pbxcp" line for that header, then it would be easy to see exactly what's going on.
I took this question over to the Xcode mailing list and had some back and forth there. It turns out that Copy Headers copies the file to a subfolder of the build folder, not to the absolute address I specified. Maybe it is not intended for what I am doing.
I've reverted to using Run Script to do the file copying.

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