Xcode 4(和依赖项)的编译、构建或存档问题

发布于 2024-10-30 17:51:38 字数 1644 浏览 6 评论 0原文

这个问题在过去几周内不断发展,涵盖了 (以及从较旧的 s)。

然而,许多问题可以通过遵循同一组说明来解决。

如果您遇到以下任何问题,请尝试接受的答案中的方法:

  • 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 

Much 谷歌搜索显示很多人遇到这个问题但没有解决方案。任何人都得到了修复,甚至是线索。

更新:在所有配置中,用户标头搜索路径均设置为${BUILT_PRODUCTS_DIR}。除了存档之外,它可以使用任何配置构建良好。

更新 2: Merchant.h 是自动生成的核心数据类,因此位于 .xcdatamodeld 包内,但是标头全部被复制构建库时到公共头目录。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

北座城市 2024-11-06 17:51:38

注意:以下步骤将解决 90% 的 Xcode 存档问题
但是,从评论中建议您尝试 退出 Xcode
第一的。这可能会节省您数小时的设置调整时间。

  1. 检查“用户标头路径”是否正确(在项目和依赖项中将“”添加到空格路径)
  2. 将“始终搜索用户路径”设置为“是”
  3. 创建组在项目中调用“索引标头”并将标头拖到此组中,请勿在出现提示时添加到任何目标。这包括 .xcdatamodeld 中的任何标头,您需要右键单击并查看包内容才能找到它们。
  4. 对于所有依赖项,将“跳过安装”构建设置设置为“是”
  5. 将构建阶段中的任何“公共”标头移动到“项目”
  6. 设置构建设置“安装”将目标上的“目录” 更改为 $(LOCAL_APPS_DIR)
  7. 将目标构建设置“扫描所有源文件以查找包含内容”更改为 YES。 )
  8. 链接 较新版本的 Xcode (> 4.2) 您可能需要 阅读此与工作区相关的问题
  9. 从所有引用的项目中手动删除project.xcworkspace文件

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
ˉ厌 2024-11-06 17:51:38

我在 XCode 4 中遇到了同样的问题:“未找到词法或预处理器问题 MyFile.h”。然而,MyFile.m 不是一个静态库,只是一个标准类。 MyFile.m 和 MyFile.h 已正确包含在项目中并建立了索引。

所以...我退出了 XCode 和模拟器,然后重新启动它们,问题就消失了。

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.

浅笑轻吟梦一曲 2024-11-06 17:51:38

我发现当我将目标构建设置“扫描所有源文件以查找包含”从“否”更改为“是”时,问题就消失了。

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

坠似风落 2024-11-06 17:51:38

我能够解决这个问题,无需对任何构建设置进行任何更改,只需将 .h 文件复制到查找器中的项目目录中即可。我根本没有将它们添加到项目中。只要将它们放在项目的文件系统目录中似乎就足以让 Xcode 的隐式链接正常工作。更多详细信息 在这里

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.

忘你却要生生世世 2024-11-06 17:51:38

我有一个像这样奇怪的问题。将“扫描所有资源文件...”更改为“是”没有帮助。我查看了框架搜索路径,注意到我有

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

它看起来是正确的,但仍然失败。然后我尝试重新排列 2 和 2 的顺序。 3 突然之间一切都变得很好了。所以不知道为什么会出现这个问题,但想将其添加到要尝试的事情列表中,以防它对其他人有帮助。

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.

且行且努力 2024-11-06 17:51:38

我的解决方案是将我的更改

#import "HeaderFile.h"

#import <FrameworkName/HeaderFile.h>

,一切都重新开始工作。
不寻常的是,它在构建后突然停止工作
几次。

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.

杀お生予夺 2024-11-06 17:51:38

设置为“是”时,问题自行解决

当我将“构建设置”->“项目”->“搜索路径”

The problem resolved itself when I set

Build Settings->Project->Search Paths to Yes

云朵有点甜 2024-11-06 17:51:38

我的项目中有相同的 2 个目标(GHUnitProjectProjectTest)。当我的方案设置为Project时,的导入出现“未找到词法或预处理器问题文件”< /em>.但是当我设置为方案ProjectTest时,一切正常。因此,我也在 Project 中添加了 GHUnitIOS.framework

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.

我不在是我 2024-11-06 17:51:38

看起来您的标头搜索路径不正确,未在活动方案的构建设置中正确配置。验证它们并使用当前设置更新您的问题。

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.

来日方长 2024-11-06 17:51:38

我在模拟器上遇到类似的问题,但在设备上没有,并且我的标题搜索路径字段为空(似乎是默认的)。但改变工作空间似乎已经解决了这个问题。也许您可以尝试创建一个新的工作区,将您的项目添加到其中,看看是否有帮助。现在我正在调查原因。

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.

无声静候 2024-11-06 17:51:38

我的项目中的一个特定 .h 文件出现了“文件未找到”错误。我通过从项目中删除该 .h 文件(选择“删除引用”)并重新添加它来解决该问题。

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.

淡看悲欢离合 2024-11-06 17:51:38

添加更多变体:我在 Compile Source 构建阶段有两个 foo.m 实例,这在某种程度上导致了 foo.h 的“找不到标头”

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.

淡笑忘祈一世凡恋 2024-11-06 17:51:38

另一个机会:

在工作区项目中:在“目标”中查看“构建阶段”部分。正如许多手册所说,您需要有一个复制文件构建阶段来将所有标头复制到另一个位置,因为 iOS 框架不能包含要共享的标头文件(这是我的情况)。

为这些复制文件选择“产品目录”作为目标选项。或者您喜欢的另一个目录,标题将驻留在其中。

这对我有用。存档(或发布)目录的构建可能与 Debug 构建中的预期非常不同。

另请检查您的工作区设置和构建目录。

XD

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

囚我心虐我身 2024-11-06 17:51:38

对我来说,这个问题是在我向项目添加新文件后发生的;从 NSObject 派生的空白 .m 和 .h。以下是我解决它的方法:

  1. 关闭并重新启动 xCode
  2. 通过 XCode 删除了两个新文件
  3. 重新编译成功

我然后重新添加了它们,它也起作用了。

绝对是 xCode 中的错误...

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文