XCode 4:修复项目导航器中的红色源文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14814606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:45:06  来源:igfitidea点击:

XCode 4: fixing red source files in the project navigator

xcodexcode4xcode4.4

提问by dB'

In an XCode project, all of my source files show up in red in the navigator. Double clicking on them does not open them in the text editor.

在 XCode 项目中,我的所有源文件在导航器中都显示为红色。双击它们不会在文本编辑器中打开它们。

The file paths are all correct in the file inspector, though, and the project compiles perfectly well.

但是,文件检查器中的文件路径都是正确的,并且项目编译得非常好。

It's as if the compiler part of xcode can find the files, but the text editor part can't.

就好像 xcode 的编译器部分可以找到文件,但文本编辑器部分不能。

Can anyone suggest how I might fix the project so that I can open the source files in the editor?

谁能建议我如何修复项目以便我可以在编辑器中打开源文件?

Curiously, I've tried deleting and re-adding the them, but this doesn't seem to work. The file names still show up in red.

奇怪的是,我尝试删除并重新添加它们,但这似乎不起作用。文件名仍然显示为红色。

Any ideas?

有任何想法吗?

采纳答案by dB'

Hm. Originally, all the troublesome files had a variable in their path, e.g. $(MY_LIBRARY_LOCATION)/src/file.cpp.

嗯。最初,所有麻烦的文件在其路径中都有一个变量,例如$(MY_LIBRARY_LOCATION)/src/file.cpp.

Originally MY_LIBRARY_LOCATIONwas an absolute path ( /Users/me/my_libs'). I first tried changing it to a relative path (../../../my_libs`). This didn't help.

最初MY_LIBRARY_LOCATION是一个绝对路径(/Users/me/my_libs'). I first tried changing it to a relative path (../../../my_libs`)。这没有帮助。

Finally, I opened up the XCode project file (myproj.xcodeproj/project.pbxproject) in a text editor and removed all references to the variable. Instead I hard-coded the absolute paths to all the files (e.g. /Users/me/my_libs/src/...). This solved the problem.

最后,我myproj.xcodeproj/project.pbxproject在文本编辑器中打开 XCode 项目文件 ( ) 并删除对变量的所有引用。相反,我硬编码了所有文件的绝对路径(例如/Users/me/my_libs/src/...)。这解决了问题。

It's neither elegant nor portable, but, hey, it works.

它既不优雅也不便携,但是,嘿,它有效。

回答by Khaled Barazi

Here is something similar that happened to me in git that may help. If you had recently changed the directory path of those files so that one of the folders in that path have a "/" in its name, that could cause your files to turn red and inaccessible.

这是我在 git 中发生的类似事情,可能会有所帮助。如果您最近更改了这些文件的目录路径,以便该路径中的文件夹之一在其名称中包含“/”,则可能会导致您的文件变为红色且无法访问。

Hope that is it.

希望就是这样。

回答by ArQangel

I found this too, after moving a project to a new directory. But I changed the File Path to Absolute in file inspector and it found them all. Not sure its the best way. BUt it solved my problem quickly

在将项目移动到新目录后,我也发现了这一点。但是我在文件检查器中将文件路径更改为绝对,它找到了所有文件。不确定它是最好的方法。但它很快解决了我的问题

(quick and dirty sorry!)

(又快又脏,抱歉!)

A

一种