objective-c process phases - Compile, Build or Archive problems with Xcode 4 (and dependencies)

7 Answers

I had the same problem in XCode 4: "Lexical or preprocessor issue MyFile.h not found". However, MyFile.m was not a static library, just a standard class. And MyFile.m and MyFile.h were included properly and indexed in the project.

So ... I quit XCode and the Simulator, then restarted them and the problem disappeared.

system 10 new

This question has evolved over the past several weeks to cover more general issues with xcode4 (and upgrading projects form older xcodes).

However many of the issues can be solved by following the same set of instructions.

If you have any of the following issues, try the methods in the accepted answer:

  • Xcode 4 fails to archive an App
  • Xcode 4 creates an unusable archive
  • Xcode 4 does not create an .ipa
  • Xcode 4 fails to compile due to preprocessor errors
  • Xcode 4 cannot find headers
  • Xcode 4's code complete is not working
  • Project dependancies won't compile
  • Adding a dependancy causes any of the above issues

Original Question

Title: "lexical or preprocessor issue file not found" in Xcode 4

I have a project in Xcode 4 that will build fine and run on the device and simulator but when trying to Archive it errors when looking for headers files associated with a static library:

In file included from /Volumes/Development/Path/LBProject/LBProject/LBProject-Prefix.pch:15:
In file included from /Volumes/Development/Path/LBProject/LBFDefines.h:23:
In file included from /Volumes/Development/Path/LBProject/Classes/LBProjectAppDelegate.h:11:
In file included from /Volumes/Development/Path/LBProject/LBProject/../FKNDirectory/FKNDirectoryManager.h:10:
/Volumes/Development/Path/LBProject/LBProject/../FKNDirectory/FKNDataModel.h:11:9: fatal error: 'Merchant.h' file not found [1]
 #import "Merchant.h"
1 error generated. 

Xcode gives the error

lexical or preprocessor issue file not found 

Much Googling has show many people are having this issue but no solution. Anyone got a fix or even a clue.

Update: The user header search paths are set to ${BUILT_PRODUCTS_DIR} in all configurations. It builds fine using any configuration except when archiving.

Update 2: Merchant.h is a Core Data class that is auto-generated and therefore inside .xcdatamodeld package, however the headers are all copied to the public headers directory when the library is built.

I was able to resolve this issue without any changes to any of the build settings by simply copying the .h files into the Project's directory in the finder. I did NOT add them to the project at all. Just having them in the project's filesystem directory seemed to be enough to allow Xcode's implicit linking to work properly. More details here.

My solution was to change my

#import "HeaderFile.h"


#import <FrameworkName/HeaderFile.h>

and everything started working again. What was unusual was that it had stopped working suddenly after building a few times.

I had the same — 2 targets in my project (Project and ProjectTest of GHUnit). When my scheme was set up to Project, the import of <GHUnitIOS/GHUnit.h> was problem of “lexical or preprocessor issue file not found”. But when I set as a scheme ProjectTest, everything was OK. So, I have added GHUnitIOS.framework in Project too.

I'm having similar issues on the simulator but not the device and my header search path fields are empty (Seems to be default). But changing Workspaces seems to have solved the issue. Maybe you could try creating a new Workspace, add your project to it and see if that helps. Now I'm investigating why.

Adding on more variant: I had two instances of foo.m in the Compile Source build phase, which some how caused "Header not found" for foo.h.

For me, this issue occurred after I added new files to the project; a blank .m and .h derived from NSObject. Here's how I resolved it:

  1. Closed and restarted xCode
  2. Deleted the two new files via XCode
  3. Recompiled successfully

I then Re-added them afterward and it also worked.

Definitely a bug in xCode...