xcode 未找到库 OpenCV

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

Library not found OpenCV

xcodeopencv

提问by Andrea F

I'm on mac 10.7.5, using xcode 4.6.2 and working with the OpenCV 2.4.3 library. I went through the process of making the build directory with the cmake files in terminal and did the download.

我在 mac 10.7.5 上,使用 xcode 4.6.2 并使用 OpenCV 2.4.3 库。我完成了在终端中使用 cmake 文件创建构建目录的过程并进行了下载。

I added the .dylibfiles in Xcode and changed the header path, changed C++ Library to libstdc++, but when I compiled I got this error :

.dylib在 Xcode 中添加了文件并更改了头文件路径,将 C++ 库更改为 libstdc++,但是当我编译时出现此错误:

ld: library not found for -lopencv_calib3d.2.4.3
clang: error: linker command failed with exit code 1 

I have libopencv_calib3d.2.4.3.dylibadded in the project so I have no idea what else it needs.Any ideas?

我已经libopencv_calib3d.2.4.3.dylib添加到项目中,所以我不知道它还需要什么。有什么想法吗?

回答by kamjagin

If your "make back-end" is Cmake you should stick to using it. Local config changes in Xcode can "secretly" be overwritten when the cmake is rerun (which for example happens after you make changes to it) creating weird build errors and forcing you to remember all the manual changes you made.

如果你的“后端”是 Cmake,你应该坚持使用它。Xcode 中的本地配置更改可能会在重新运行 cmake 时“秘密地”被覆盖(例如,在您对其进行更改后发生)创建奇怪的构建错误并迫使您记住您所做的所有手动更改。

Your problem seems to be that the generated project doesn't seem to know where to look for opencv.

您的问题似乎是生成的项目似乎不知道在哪里寻找opencv。

Assuming you installed opencv using macports you should add a line saying

假设您使用 macports 安装了 opencv,您应该添加一行说

link_directories(/opt/local/lib) 

to your CMakeLists.txt. (if you installed it using brew, or compiled it manually just replace /opt/local/libfor /usr/local/libor the path to your compiled libraries)

到您的 CMakeLists.txt。(如果您使用 brew 安装它,或者手动编译它,只需替换/opt/local/lib/usr/local/lib或编译库的路径)

Also make sure to link against opencv_calib3dinstead of opencv_calib3d.2.4.3(unless you have a very particular reason for bypassing this, but that usually means that something else is weird in the setup :) )

还要确保链接到opencv_calib3d而不是opencv_calib3d.2.4.3(除非你有一个非常特殊的原因绕过这个,但这通常意味着设置中的其他东西很奇怪:))

Final pointer that you might already know of: As you are already using Cmake you should add the libraries to link against using TARGET_LINK_LIBRARIES(...) in Cmake rather than manually adding them in Xcode (referring to my previous argument).

您可能已经知道的最终指针:由于您已经在使用 Cmake,因此您应该在 Cmake 中使用 TARGET_LINK_LIBRARIES(...) 添加要链接的库,而不是在 Xcode 中手动添加它们(参考我之前的论点)。