将 Xcode 升级到 4.5.2 并将 OpenCV 升级到 2.4.3 后出现链接器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14030546/
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
Linker errors after upgrading Xcode to 4.5.2 and OpenCV to 2.4.3
提问by Darkshore Grouper
My project was working just fine until this morning. I was using xcode 4.3, and an older version of OpenCV (I'm not sure about the exact version). OSX was already 10.7.x, but not 10.7.5
Today, after upgrading OSX to 10.7.5, xcode to 4.5.2, and downloading OpenCV 2.4.3, I am getting the following linker errors when trying to build the project:
直到今天早上,我的项目都运行良好。我使用的是 xcode 4.3 和旧版本的 OpenCV(我不确定确切的版本)。OSX 已经是 10.7.x,但不是 10.7.5
今天,在将 OSX 升级到 10.7.5、xcode 到 4.5.2 并下载 OpenCV 2.4.3 之后,我在尝试构建项目时收到以下链接器错误:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_ALAssetsLibrary", referenced from:
objc-class-ref in opencv2(cap_ios_video_camera.o)
"cv::FeatureDetector::create(std::string const&)", referenced from:
-[ImageAnalyzer detectBlobs:] in ImageAnalyzer.o
"cv::FeatureDetector::detect(cv::Mat const&, std::vector >&, cv::Mat const&) const", referenced from:
-[ImageAnalyzer detectBlobs:] in ImageAnalyzer.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
架构 armv7 的未定义符号:
“_OBJC_CLASS_$_ALAssetsLibrary”,引用自:
opencv2(cap_ios_video_camera.o) 中的 objc-class-ref
“cv::FeatureDetector::create(std::string const&)”,引用自:
-[ImageAnalyzer detectBlobs:] in ImageAnalyzer.o
"cv::FeatureDetector::detect(cv::Mat const&, std::vector >&, cv::Mat const&) const",引用自:
-[ImageAnalyzer detectBlobs:] in ImageAnalyzer。 ø
LD:符号(多个)未找到架构的ARMv7
铛:错误:连接器命令,退出代码1失败(使用-v看调用)
In order to use the new opencv framework I removed the reference to the old framework, and referenced the project to the official prebuilt opencv2.framework downloaded from here.
I also removed the reference to libz.dylib, and added a reference to libc++.dylibinstead.
Last step was to update the prefix file to the new framework. The relevant part in the prefix file now looks like this:
为了使用新的opencv框架,我删除了对旧框架的引用,并将项目引用到从这里下载的官方预构建的opencv2.framework 。
我还删除了对libz.dylib的引用,并添加了对libc++.dylib的引用。
最后一步是将前缀文件更新为新框架。前缀文件中的相关部分现在看起来像这样:
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
It all narrowed down to these 4 linker errors I can't seem to get rid of. I tried using libstdc++.dylib, but I am getting even more errors. I also tried building OpenCV myself as explained here, but I am still getting the same errors as the prebuilt framework.
What did I miss? Is there anything else I need to change in my project?
UPDATE:
As seen here, setting the "C++ Standard Library" to "libc++ (LLVM C++ standard libray with C++ 11 support" yielded only one error:
这一切都归结为这 4 个我似乎无法摆脱的链接器错误。我尝试使用libstdc++.dylib,但出现更多错误。我还尝试按照此处的说明自行构建 OpenCV ,但我仍然遇到与预构建框架相同的错误。
我错过了什么?我的项目还有什么需要改变的吗?
更新:
可以看出这里的“C ++标准库”设置为“++的libc(LLVM C ++标准libray与C ++ 11的支持”只产生一个错误:
clang: error: invalid deployment target for -stdlib=libc++ (requires iOS 5.0 or later)
clang:错误:-stdlib=libc++ 的部署目标无效(需要 iOS 5.0 或更高版本)
Changing the deployment target to iOS 5 finally got my project to run again.
Does this mean OpenCV 2.4.3 doesn't work on iOS versions older than 5?
将部署目标更改为 iOS 5 终于让我的项目再次运行。
这是否意味着 OpenCV 2.4.3 不适用于 5 之前的 iOS 版本?
采纳答案by Darkshore Grouper
Since I can't seem to get an answer regarding the versions (neither here nor at the OpenCV Q&A site), I'm going to post this as an answer, as it at least solved the issue. This is described here.
In your project's Build Settings, go down to the section Apple LLVM compiler 4.1-Language.
There:
Set C++ Language Dialectto Compiler Default
Set C++ Standard Librayto libc++ (LLVM C++ standard libray with C++ 11 support
After doing the above, I stopped getting those linker errors, and only got one error instead, which stated that only iOS 5 and above is supported. Changing the Deployment Targetto 5.0 in the project summery did the trick.
On a final note, I'm still not sure what it means, regarding OpenCV 2.4.3's compatibility with iOS versions older than 5.
由于我似乎无法得到有关版本的答案(无论是在此处还是在 OpenCV 问答网站上),我都会将此作为答案发布,因为它至少解决了问题。这在此处进行了描述。
在项目的Build Settings 中,转到Apple LLVM compiler 4.1-Language 部分。
那里:
将C++ 语言方言设置为编译器默认
设置将C++ 标准库设置为libc++(支持 C++ 11 的 LLVM C++ 标准库
在执行上述操作后,我不再收到这些链接器错误,而是只收到一个错误,其中指出只有 iOS 5 和以上是支持的。更改部署目标到 5.0 在项目总结中做到了。
最后一点,关于 OpenCV 2.4.3 与 5 之前的 iOS 版本的兼容性,我仍然不确定这意味着什么。
回答by
steps to compile and run c++ opencv 2.4.4 on mac os x lion 10.7.5 with cmake 2.8.10 and xcode 4.6.1
使用 cmake 2.8.10 和 xcode 4.6.1 在 mac os x lion 10.7.5 上编译和运行 c++ opencv 2.4.4 的步骤
Having the right tools
拥有合适的工具
- download opencv-unix from http://sourceforge.net/projects/opencvlibrary/files/and untar it wherever
- download cmake .dmg from http://www.cmake.org/cmake/resources/software.htmland install it
- i am assuming you have xcode 4.6 on os x lion which includes the ios sdk 6.1
- go to xcode preferences to download and install the Command Line Tools so you have g++ etc.
- 从http://sourceforge.net/projects/opencvlibrary/files/下载 opencv-unix并在任何地方解压
- 从http://www.cmake.org/cmake/resources/software.html下载 cmake .dmg并安装它
- 我假设您在 os x lion 上有 xcode 4.6,其中包括 ios sdk 6.1
- 转到 xcode 首选项下载并安装命令行工具,以便您拥有 g++ 等。
Use cmake to compile opencv
使用cmake编译opencv
- go to the extracted opencv folder
create a build directory
mkdir build cd build cmake -D WITH_TBB=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_FAT_JAVA_LIB=OFF -D BUILD_TBB=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_COMPILER=g++ CMAKE_CC_COMPILER=gcc -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_opencv_java=OFF -G "Unix Makefiles" .. make -j8 sudo make install
from the build folder, go to bin/ and run one of the tests
./opencv_test_stitching
- 转到解压缩的 opencv 文件夹
创建构建目录
mkdir build cd build cmake -D WITH_TBB=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_FAT_JAVA_LIB=OFF -D BUILD_TBB=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_COMPILER=g++ CMAKE_CC_COMPILER=gcc -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_opencv_java=OFF -G "Unix Makefiles" .. make -j8 sudo make install
从 build 文件夹,转到 bin/ 并运行其中一项测试
./opencv_test_stitching
Create your own c++ opencv xcode project
创建自己的 c++ opencv xcode 项目
- fire up xcode and create a new xcode project
- select Command Line Tool for the type of project under os x
- open your project's build settings
- under Architectures, set Architecture to 64-bit intel. also set Valid Architectures to x86_64
- under Build Options, set Compiler for C/C++ to Default Compiler
- under Search Paths, set Header Search Paths to /usr/local/include
- also under Search Paths, set Library Search Paths to /usr/local/lib
- under Apple LLVM compiler 4.2 - Language set C++ Standard Library to libstd++ (For OpenCV 2.4.6, Xcode 5, LLVM 5.0, and 10.8.5, set both language dialect and std library to "Compiler Default" instead of "libstd++")
- 启动 xcode 并创建一个新的 xcode 项目
- 选择 os x 下项目类型的命令行工具
- 打开项目的构建设置
- 在 Architectures 下,将 Architecture 设置为 64-bit intel。还将有效架构设置为 x86_64
- 在 Build Options 下,将 Compiler for C/C++ 设置为 Default Compiler
- 在搜索路径下,将标题搜索路径设置为 /usr/local/include
- 同样在搜索路径下,将库搜索路径设置为 /usr/local/lib
- 在 Apple LLVM 编译器 4.2 下 - 语言将 C++ 标准库设置为 libstd++(对于 OpenCV 2.4.6、Xcode 5、LLVM 5.0 和 10.8.5,将语言方言和标准库都设置为“编译器默认”而不是“libstd++”)
Add the compiled opencv libraries to your project
将编译好的 opencv 库添加到您的项目中
- go the the Build Phases tab next to Build Settings tab you were in
- inside Link Binary With Libraries, click on the + sign and choose Add Other
- hit the front slash / on your keyboard and enter /usr/local/lib
- hit enter and select the libraries you want to use in your project
- make sure you always select libopencv_core.2.4.4.dylib
- hit enter and you will see the selected dylibs under your project
- 转到您所在的“构建设置”选项卡旁边的“构建阶段”选项卡
- 在 Link Binary With Libraries 中,单击 + 号并选择添加其他
- 按键盘上的前斜杠 / 并输入 /usr/local/lib
- 按 Enter 键并选择要在项目中使用的库
- 确保您始终选择 libopencv_core.2.4.4.dylib
- 按回车键,您将在您的项目下看到选定的 dylib
write some code
写一些代码
- first lets organize the files, right click on your project blueprint icon and select New Group
- name the new group opencv or whatever
- drag the dylibs and drop them in that group
- open main.cpp
- copy code from any of the sample tests that came with opencv and paste it here
- make sure all the required dylibs are added, for example, if you copied the opencv_test_stitching.cpp code into main.cpp, you will need to add the following libraries in the previous steps libopencv_core.2.4.4.dylib libopencv_highgui.2.4.4.dylib libopencv_stitching.2.4.4.dylib
- 首先让我们组织文件,右键单击您的项目蓝图图标并选择新建组
- 将新组命名为 opencv 或其他任何名称
- 将 dylib 拖放到该组中
- 打开 main.cpp
- 从 opencv 附带的任何示例测试中复制代码并将其粘贴到此处
- 确保添加了所有必需的dylib,例如,如果您将opencv_test_stitching.cpp 代码复制到main.cpp 中,则需要在前面的步骤libopencv_core.2.4.4.dylib libopencv_highgui.2.4.4 中添加以下库。 dylib libopencv_stitching.2.4.4.dylib
Cheers.
干杯。
回答by Codo
It seems that your project is missing the framework AssetsLibrary.
您的项目似乎缺少框架AssetsLibrary。
Select the top node in the project navigator. (The project and targets page with the build settings appears.)
Select the target.
Select Summary.
Scroll down to Linked Frameworks and Libraries.
Click the Plusicon at the end of the table and select AssetsLibrary.framework.
Click Add.
在项目导航器中选择顶部节点。(带有构建设置的项目和目标页面出现。)
选择目标。
选择摘要。
向下滚动到链接的框架和库。
单击表末尾的加号图标并选择AssetsLibrary.framework。
单击添加。
Then try to build it again.
然后尝试再次构建它。
回答by Rahul
clang: error: invalid deployment target for -stdlib=libc++ (requires iOS 5.0 or later) to remove this error.
clang: 错误:-stdlib=libc++ 的无效部署目标(需要 iOS 5.0 或更高版本)以消除此错误。
GoTo BuildSettings. Set c++ standard library to compiler default. The error will get removed surely.
转到构建设置。将 c++ 标准库设置为编译器默认值。错误肯定会被删除。
回答by TimIam
Just to get this into the postings somewhere in case someone else runs into the same thing. If you follow all the great advice aboutsetting the proper c++ library to link against for building an iOS app BUT still get the link errors for undefined symbols make sure your code files are set to compile as c++! That is rename your .m to .mm and .h to .hpp. It's the little things...
只是为了将其放入某处的帖子中,以防其他人遇到同样的事情。如果您遵循有关设置正确的 C++ 库以链接以构建 iOS 应用程序的所有重要建议,但仍然收到未定义符号的链接错误,请确保您的代码文件设置为编译为 C++!那就是将您的 .m 重命名为 .mm,将 .h 重命名为 .hpp。都是小事...
回答by Khawar Ali
Instead of using terminal commands given in the opencv installation guide in official website, use the following commands to build opencv from terminal. Worked for me.
不使用官网opencv安装指南中给出的终端命令,而是使用以下命令从终端构建opencv。对我来说有效。
cd OpenCV-2.3.1
cd OpenCV-2.3.1
mkdir build
mkdir 构建
cd build
光盘构建
cmake -G "Unix Makefiles" ..
cmake -G "Unix Makefiles" ..
make
制作
sudo make install
须藤制作安装
回答by Mihail Salari
- Go Xcode/General/Linked Frameworks and Libraries
- Press "+" button
- type: AssetsLibrary
- Select "AssetsLibrary.framework" and import it
- Go Xcode/General/Linked Frameworks and Libraries
- 按“+”键
- 类型:资产库
- 选择“AssetsLibrary.framework”并导入
Done
完毕
Good luck!
祝你好运!