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

14

96

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

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.

Hypesthesia answered 7/4, 2011 at 16:22 Comment(0)
H
119

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
Hypesthesia answered 9/4, 2011 at 19:39 Comment(8)
The very last suggestion is all I needed to fix this issue. Close & re-open Xcode.Hathor
Yup, same thing for me, just had to restart Xcode. It happened after I renamed & moved files around in the project.Burglarious
Me too. Nothing more frustrating than a bug that shouldn't exist. Great to have it resolved so easily.Staggers
Note to Three20 users migrating old projects from xcode3 to xcode4 : you (may) have to change xcode Preference / locations / advanced / ->Locations specified by target. See stackoverflow.com/questions/5261447/… for moreHussar
I've tried all these solutions, but still have an issue with 'Lexical or Preprocessor Issue 'openssl/evp.h' file not found', the issue ONLY occurs when I open a file with the include, if I close that file and build, the error goes away, so I think some people may assume the issue has gone when in fact it's still there, that was the case with me, much loss of hair.Translocation
Holy crap on number 1. The quotes! Environment $(SRC_ROOT) of course, "may" resolve with a path with spaces. Could not figure out why zipping my project and extracting elsewhere resulted in a build failure!Wainscot
I changed the "Product Name" in Build Settings->Packages to match my project name. And fixed this issue.Nature
Step 5 worked for me, except I had to move the problematic header from Project to Public. (The XCode project that was failing to build was a library that another project of mine was using.)Scold
J
13

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.

Jiminez answered 24/4, 2011 at 17:1 Comment(1)
I had a similar situation, but the unwanted error displayed due to incorrectly referencing a unrelated property which was in the same class (basically I forgot to use self.) - strange one.Counsel
P
11

I found that the problem went away when I changed the target build setting "scan all source files for includes" from no to yes.

Proceeds answered 26/8, 2011 at 22:5 Comment(0)
L
6

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.

Lainelainey answered 14/11, 2011 at 6:14 Comment(1)
+1 I have added a link to the question int he accepted answer, thanks for the info!Hypesthesia
T
4

I had a weird issue like this. Changing "Scan all resource files..." to Yes didn't help. I took a look at the Framework Search Paths and noticed that I had

  • $(inherited)
  • "$(SRCROOT)"
  • "$(SRCROOT)/my/correct/path"

It seemed right but was still failing. I then tried rearranging the order of 2 & 3 and all of a sudden it built fine. So not sure why that was the hickup, but wanted to add it to the list of things to try in case it helps someone else.

Tautology answered 19/10, 2011 at 6:12 Comment(0)
B
4

My solution was to change my

#import "HeaderFile.h"

to

#import <FrameworkName/HeaderFile.h>

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

Boaster answered 28/5, 2013 at 3:21 Comment(2)
I tried everything else with my subproject and this was the only thing that would work. Thank you.Monastery
You should still use double-quotes for static libraries. Angle brackets search the system header paths and will not search user header paths unless you also enable the Always Search User Paths option, which you shouldn't if you don't need to.Romelda
D
2

The problem resolved itself when I set

Build Settings->Project->Search Paths to Yes

Devault answered 8/11, 2011 at 18:7 Comment(0)
Q
2

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.

Quadruplicate answered 12/5, 2012 at 15:30 Comment(1)
I had the opposite issue. See my answer: https://mcmap.net/q/16487/-compile-build-or-archive-problems-with-xcode-4-and-dependenciesBoaster
A
1

Looks like your header search paths are incorrect not configured properly in your build settings for the active scheme. Verify them and update your question with the current setting.

Abundance answered 7/4, 2011 at 17:0 Comment(0)
A
1

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.

Altonaltona answered 8/4, 2011 at 18:16 Comment(0)
A
1

I was getting this "file not found" error for one particular .h file in my project. I resolved the issue by removing that .h file from the project (selecting "Remove references") and re-adding it.

Abduction answered 25/5, 2011 at 0:55 Comment(0)
K
1

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.

Krishnakrishnah answered 24/11, 2011 at 6:44 Comment(0)
B
1

Another chance:

In workspace project: watch in the Target for section Build Phases. As many manuals says you need to have a Copy Files Build Phase to copy all your headers to another place, as iOS Framework cannot contain header files to be shared (this is my case).

Choose for those Copy Files as Destination option "Products Directory". Or another directory of your like where the headers will reside.

That worked for me. Probably the build for Archive (or Release) directory is very different than expected in build for Debug .

Also check in your workspace settings your build directory.

XD

Biddie answered 30/1, 2013 at 21:17 Comment(0)
T
0

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

Typhoid answered 4/7, 2012 at 4:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.