使用 Xcode 4编译、构建或存档问题(以及依赖项)

这个问题在过去的几个星期里已经发展到涵盖 的更多一般性问题(以及从旧的 升级项目)。

然而,许多问题可以通过遵循相同的指令集来解决。

如果你有以下任何一个问题,请尝试接受答案中的方法:

  • Xcode 4无法归档应用程序
  • Xcode 4创建了一个不可用的归档文件
  • Xcode 4不创建. ipa
  • 由于预处理器错误,Xcode 4编译失败
  • Xcode 4找不到头文件
  • Xcode 4的代码完整无效
  • 项目依赖关系无法编译
  • 添加依赖项会导致上述任何问题

原始问题

标题: 在 Xcode 4中“未找到词法或预处理器问题文件”

我在 Xcode 4中有一个项目,它可以很好地构建并在设备和模拟器上运行,但是当试图存档它时,在寻找与静态库相关的头文件时会出错:

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 显示错误

lexical or preprocessor issue file not found

很多谷歌搜索显示,很多人都有这个问题,但没有解决方案。任何人都有定位,甚至是线索。

更新: 在所有配置中,user header搜索路径都设置为 ${BUILT_PRODUCTS_DIR}。它使用除归档时的任何配置构建良好。

更新2: Merchant.h是一个自动生成的 Core Data 类,因此在 .xcdatamodeld包中,但是在构建库时,所有的头都被复制到公共头目录中。

80892 次浏览

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.

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.

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

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.

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.

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

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.

The problem resolved itself when I set

Build Settings->Project->Search Paths to Yes

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.

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.

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.

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

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

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.