ios 在 Xcode 中找不到 opencv2/opencv.hpp 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34429936/
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
opencv2/opencv.hpp file not found in Xcode
提问by Anirudh GP
I have built openCV to get opencv2.framework. I added this to my xcode iOS project by going to "build phases->Link Binary With Libraries", then tried to include "opencv2/opencv.hpp" in my project. I get the error "opencv2/opencv.hpp" not found. But the file exists in the framework. I have tried to find a solution online but nothing has worked for me.
我已经构建了 openCV 来获取 opencv2.framework。我通过转到“构建阶段->链接二进制与库”将其添加到我的 xcode iOS 项目中,然后尝试在我的项目中包含“opencv2/opencv.hpp”。我收到错误“找不到 opencv2/opencv.hpp”。但是该文件存在于框架中。我试图在网上找到解决方案,但没有任何效果。
The file I'm trying to include it in is a .mm file. I have made "compile sources as" objective-c++. Any help would be great.
我试图包含它的文件是一个 .mm 文件。我已经“将源代码编译为”objective-c++。任何帮助都会很棒。
采纳答案by Anirudh GP
Took me 4 hours to figure this out. This is how I got this to work : Along with the opencv framework add the following frameworks in the build phases:
我花了 4 个小时才弄清楚这一点。这就是我让它工作的方式:与 opencv 框架一起在构建阶段添加以下框架:
Accelerate, AssetsLibrary, AVFoundation , CoreGraphics , CoreImage , CoreMedia , CoreVideo , QuartzCore , UIKit , Foundation.
加速、AssetsLibrary、AVFoundation、CoreGraphics、CoreImage、CoreMedia、CoreVideo、QuartzCore、UIKit、Foundation。
Then, in the .pch file add these lines before UIKit and Foundation imports :
然后,在 .pch 文件中,在 UIKit 和 Foundation 导入之前添加这些行:
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
回答by N.Atanasov
What worked for me was very simple:
对我有用的很简单:
*NOTE THE DIFFERENCE FOR IOS vs. OS X PROJECTS
*注意 IOS 与 OS X 项目的区别
FOR IOS:
对于 IOS:
Put the opencv download (for 3.0.0 it is just a drag and drop kind of thing) into the project specific Xcode folder. Then set the Frame Search Pathsto $(PROJECT_DIR). The Frame Search Path is located under the Build Settings. No other paths need to be set.
将 opencv 下载(对于 3.0.0,它只是一种拖放操作)放入项目特定的 Xcode 文件夹中。然后将框架搜索路径设置为 $(PROJECT_DIR)。Frame Search Path 位于Build Settings 下。无需设置其他路径。
Lastly, right click in the navigator pane and click "Add Files to..." in order to add in the opencv library from the project folder.
最后,右键单击导航器窗格并单击“将文件添加到...”,以便从项目文件夹中添加 opencv 库。
FOR OSX:
对于 OSX:
check out Tim's tutorial: https://www.youtube.com/watch?v=OVSPfUmNyOw
查看 Tim 的教程:https: //www.youtube.com/watch?v=OVSPfUmNyOw
回答by Alex Reche Martinez
回答by Ekkelenkamp
In my case the symbolic links to the header files were broken. This was caused by cloning the following great example project:
在我的情况下,头文件的符号链接被破坏了。这是由克隆以下优秀示例项目引起的:
https://github.com/BloodAxe/OpenCV-Tutorial
https://github.com/BloodAxe/OpenCV-教程
In the cloned project, the header files were not reachable anymore. After reimporting the opencv2.framework from the official opencv ios download site (OpenCV for iOS), the headers were available again. XCode should look as follows:
在克隆的项目中,无法再访问头文件。从官方 opencv ios 下载站点 ( OpenCV for iOS)重新导入 opencv2.framework 后,头文件再次可用。XCode 应如下所示:
The following is a screenshot of a Xcode project with broken headers. With broken header files, the xcode project looks as follows:
以下是标头损坏的 Xcode 项目的屏幕截图。使用损坏的头文件,xcode 项目如下所示:
回答by Evan Bauer
Make sure in Build Settingsfor the Target, you have the Framework Search Path in the Search Pathssection set to the correct path to where your framework is located in your directory. You can do this by clicking to the right of Framework Search Pathin the white space, click the + sign and add $(PROJECT_DIR) then click + again and add $(inherited). Make sure the framework is located in your main directory for your project at hand. This worked for me, as I encountered the same problem.
确保在目标的构建设置中,将搜索路径部分中的框架搜索路径设置为框架在目录中所在位置的正确路径。您可以通过单击空白处框架搜索路径的右侧,单击 + 号并添加 $(PROJECT_DIR) 然后再次单击 + 并添加 $(inherited) 来执行此操作。确保框架位于您手头项目的主目录中。这对我有用,因为我遇到了同样的问题。
Hope this helps!
希望这可以帮助!
回答by C0mrade
I used openCV in my project and implementing it with cocoapods
was impossible because version of library was too old, so i decided to implement it as static library. create folder in your project and add library there, in build settings find library
and framework
search path and add link to your openCV
folder. It will work without any error. Also you should add openCV header file in prefixPatch
.
我在我的项目中使用了 openCV 并且cocoapods
无法实现它,因为库的版本太旧了,所以我决定将它实现为静态库。在您的项目中创建文件夹并在那里添加库,在构建设置中查找library
和framework
搜索路径并将链接添加到您的openCV
文件夹。它将正常工作而不会出现任何错误。您还应该在prefixPatch
.
More Detail Instruction 100% Works:
更详细的说明 100% 有效:
1) Download framework from official website: OpenCV
1) 从官网下载框架:OpenCV
2) In Project Directorycreate folder named: External_SDK
2) 在项目目录中创建名为:External_SDK 的文件夹
3) Put Opencvframework inside this folder and drag&drop it in Xcode Project (Folder) with Target Membership of your App (Not App_test).
3) 将Opencv框架放在此文件夹中,然后将其拖放到 Xcode 项目(文件夹)中,并使用您的应用程序的目标成员身份(不是 App_test)。
4) In Xcode Project search for yourPrefixHeaderFileName.pch
and in the top of the file add this lines:
4) 在 Xcode Project 中搜索yourPrefixHeaderFileName.pch
并在文件顶部添加以下行:
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
5) after that you should importor includeit in .hfile, why include? because it's CPP library. If you want to access library with import keywoard than you should do like this: #import <EXAMPLE>
5) 之后,您应该将其导入或包含在.h文件中,为什么要包含?因为它是 CPP 库。如果您想使用 import 关键字访问库,则应该这样做:#import <EXAMPLE>
6) In build settings search for libraryand frameworksearch path and add link to your EXTERNAL_SDKfolder. To read framework directly from your folder. Find and change ALWAYS_SEARCH_USER_PATHS = YESand in HEADER_SEARCH_PATHSadd $(inherited)and /usr/include/FRAMEWORK_PATH
6) 在构建设置中搜索库和框架搜索路径并将链接添加到您的EXTERNAL_SDK文件夹。直接从您的文件夹中读取框架。查找并更改ALWAYS_SEARCH_USER_PATHS = YES并在HEADER_SEARCH_PATHS添加$(inherited)和 /usr/include/FRAMEWORK_PATH
Hope this answer will help someone.
希望这个答案会对某人有所帮助。
And the best practice is to call
最好的做法是调用
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
Only header files.
只有头文件。
回答by Jeff
From my experience, it is not necessary to add so many other frameworks. Instead, only need opencv2 and add "#import " in prefixheader.pch
根据我的经验,没有必要添加这么多其他框架。相反,只需要 opencv2 并在 prefixheader.pch 中添加“#import”
The thing is that MUST set correct Framework Search Paths as mentioned above unless opencv2 framework folder is in your project directory.
问题是必须如上所述设置正确的框架搜索路径,除非 opencv2 框架文件夹在您的项目目录中。
Notice: don't set wrong location in Framework Search Paths as there are two "YourProjectName". Set the 1st one (belongs to TARGETS), not the 2nd one(belongs to PROJECT). I made the mistake.
注意:不要在框架搜索路径中设置错误的位置,因为有两个“YourProjectName”。设置第一个(属于 TARGETS),而不是第二个(属于 PROJECT)。我犯了错误。
回答by River Hsu
Here is my answer for this.
这是我对此的回答。
Environment: XCode 8.1
Download page: http://opencv.org/downloads.html. Choose any link for iOS.
Important step: while downloading opencv2.framework, you must use ".zip" format, not ".framework" format, afterwards, unzip it to opencv2.framework. It is weird, but it should work. Meanwhile, you have to rename it to opencv2.framework if the unzipped one is not.
just drag and drop the framework to your iOS project. No any settings are required. You could refer to this for testing : www.youtube.com/watch?v=ywUBHqxwM5Q.
环境:XCode 8.1
下载页面:http: //opencv.org/downloads.html。为 iOS 选择任何链接。
重要步骤:下载opencv2.framework时,必须使用“.zip”格式,而不是“.framework”格式,然后解压到opencv2.framework。这很奇怪,但它应该有效。同时,如果解压缩的不是,则必须将其重命名为 opencv2.framework。
只需将框架拖放到您的 iOS 项目中即可。不需要任何设置。你可以参考这个进行测试:www.youtube.com/watch?v=ywUBHqxwM5Q。
回答by Mario Antonio Alvarez Enriquez
I ran into some issues when I went to Target-->Build Phases-->Link Binary With Libraries. When I added opencv2.framework from there, my app would not launch.
当我转到 Target-->Build Phases-->Link Binary With Libraries 时遇到了一些问题。当我从那里添加 opencv2.framework 时,我的应用程序无法启动。
Instead, I just dragged and dropped the framework under the directory "Frameworks" in XCode and that worked. I didn't change anything else.
相反,我只是将框架拖放到 XCode 中的“Frameworks”目录下,然后就可以了。我没有改变其他任何东西。