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

80,675

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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.

Solution 5

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.

Share:
80,675
Richard Stelling
Author by

Richard Stelling

Tech geek and hopelessly optimistic about my pessimistic outlook. http://www.richardstelling.com http://twitter.com/rjstelling http://careers.stackoverflow.com/rjstelling SOreadytohelp

Updated on July 08, 2020

Comments

  • Richard Stelling
    Richard Stelling almost 4 years

    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.