xcode 导入“cocos2d.h”适用于某些文件,但不是全部

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9799130/
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-14 23:44:19  来源:igfitidea点击:

import "cocos2d.h" works in some files, but not all

objective-cxcodeimportcocos2d-iphonefile-not-found

提问by Pterie Daktyl

Here is what I did:

这是我所做的:

In Xcode 4.3.1

在 Xcode 4.3.1 中

File -> New -> Project -> Single view application

文件 -> 新建 -> 项目 -> 单视图应用程序

Dragged the file cocos2d-ios.xcodeproj into navigator.

将文件 cocos2d-ios.xcodeproj 拖入导航器。

In build phases settings : Added : libcocos2d.a (becomes highlighted in red), as a linked library (required).

在构建阶段设置中:添加:libcocos2d.a(以红色突出显示),作为链接库(必需)。

Added OpenGles.framework, Quartzcore, and libz.dylib

添加了 OpenGles.framework、Quartzcore 和 libz.dylib

Changed build settings - Set "Always Search User Paths" to YES Added cocos2d source directory to "User Header Search Paths"

更改构建设置 - 将“始终搜索用户路径”设置为“是”将 cocos2d 源目录添加到“用户标题搜索路径”

Now, it seems I can type: import "cocos2d.h" , in the app delegate and root view controller that Xcode created. But if I create a new file, and I add the line "import "cocos2d.h"" to the top, Xcode complains that the file is not found. But it seems to build fine. Also, in this new file code sense does not work.

现在,我似乎可以在 Xcode 创建的应用程序委托和根视图控制器中输入: import "cocos2d.h" 。但是,如果我创建一个新文件,并在顶部添加“import "cocos2d.h"” 行,Xcode 会抱怨找不到该文件。但它似乎构建得很好。此外,在这个新文件中,代码意义不起作用。

What should I do? Why can I import only in the files that Xcode created? Is there some setting I need to change so that in the files I create, I can import cocos2d ?

我该怎么办?为什么我只能在 Xcode 创建的文件中导入?是否需要更改某些设置,以便在我创建的文件中导入 cocos2d ?

EDIT: It seems to build and run fine. I can call methods in the cocos2d api. code sense just doesn't seem to see cocos2d.h in the new files I create.

编辑:它似乎构建和运行良好。我可以调用 cocos2d api 中的方法。代码意识似乎没有在我创建的新文件中看到 cocos2d.h。

EDIT - it seems that code sense suggests cocos2d.h when i type : import " But it does not suggest classes / methods from the cocos2d api.

编辑 - 当我输入时,代码感觉似乎建议 cocos2d.h : import " 但它不建议来自 cocos2d api 的类/方法。

采纳答案by Pterie Daktyl

Turns out I had only added the "user header search paths" to my target, but not in the project settings.

结果我只在我的目标中添加了“用户标题搜索路径”,而不是在项目设置中。

Adding it fixed the problem. I guess the reason it compiled fine was because I had added it to the target, but it didn't work in the text editor since I hadn't added it to the project.

添加它解决了问题。我猜它编译良好的原因是因为我已将它添加到目标中,但它在文本编辑器中不起作用,因为我没有将它添加到项目中。

回答by Questor

This happened to me as well, even though I did add it to both project and target.

这也发生在我身上,即使我确实将它添加到了项目和目标中。

However, what worked for me was to select the RECURSIVE checkbox under "User Header Search Prefixes" (which was set to "/lib/**")

但是,对我有用的是选择“用户标题搜索前缀”下的递归复选框(设置为“/lib/**”)

回答by Neil Galiaskarov

I had same issue.

我有同样的问题。

My project -> Build Settings
Look for the entry for Search Paths

我的项目 -> 构建设置
查找搜索路径的条目

Always Search User Paths- YES

始终搜索用户路径-

User Header Search paths- "myProjectName/libs" //I put box2d folder here

User Header Search paths- "myProjectName/libs" //我把box2d文件夹放在这里

Hope this help someone.

希望这有助于某人。