未定义的符号,mac 上 opencv2.3.1 中的 cvSmooth

发布于 2025-01-04 21:25:03 字数 181 浏览 0 评论 0原文

我是Opencv的初学者。最近我遇到了有关 cvSmooth 的问题。当我尝试使用 Xcode 编译它时,编译器给了我一个错误: 未定义的符号: “_cvSmooth”,引用自: main.o 中的 _main ld:未找到符号 Collect2: ld 返回 1 退出状态

有谁知道导致此问题的原因是什么?谢谢你!

I am a beginner of Opencv. Recently I came across about problem about cvSmooth. When I tried to compile it using Xcode, the compiler gave me an error saying,
Undefined symbols:
"_cvSmooth", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Does anyone know what causes this problem? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烧了回忆取暖 2025-01-11 21:25:03

OpenCV 编译了许多库。如果您像我一样从 OpenCV 教程开始(我正在使用 O'Reilly 的书),您可以添加 libopencv_core.dyliblibopencv_highgui.dylib ,它们可以正常工作直到使用cvSmooth函数。

链接器错误(未定义的符号)是“您尚未链接所有必要的库,因此我找不到您要求的例程”的代码。使用 nm 命令可以轻松找到它们,有时您可以通过提供您认为可能位于其中的库来帮助搜索:

joe@macmini:/usr/local/lib [master]
$ nm libopencv_imgproc*|grep cvSmooth
0000000000132a60 T _cvSmooth
0000000000132a60 T _cvSmooth
0000000000132a60 T _cvSmooth

将 libopencv_imgproc.dylib 添加到您的 Xcode 项目你应该去参加比赛了。

PS:由于针对基础库的软链接, _cvSmooth 显示了 3 次:

$ ls -l libopencv_img*
-rwxr-xr-x  1 root  admin  2063132 Feb 16 17:48 libopencv_imgproc.2.4.8.dylib*
lrwxr-xr-x  1 root  admin       29 Feb 16 17:48 libopencv_imgproc.2.4.dylib@ -> libopencv_imgproc.2.4.8.dylib
lrwxr-xr-x  1 root  admin       27 Feb 16 17:48 libopencv_imgproc.dylib@ -> libopencv_imgproc.2.4.dylib

OpenCV compiles a number of libraries. If you're like me and started out with the OpenCV tutorials (I'm using the O'Reilly book) you added libopencv_core.dylib and libopencv_highgui.dylib which worked up until using the cvSmooth function.

Linker errors (undefined symbols) are code for "you haven't linked against all of the necessary libraries and therefore I can't find the routine you've asked for." They can be easy to find with the nm command, sometimes you can help the search by providing the library you think it might be in:

joe@macmini:/usr/local/lib [master]
$ nm libopencv_imgproc*|grep cvSmooth
0000000000132a60 T _cvSmooth
0000000000132a60 T _cvSmooth
0000000000132a60 T _cvSmooth

Add libopencv_imgproc.dylib to your Xcode project and you should be off to the races.

PS: _cvSmooth shows up 3 times because of the soft links against the base library:

$ ls -l libopencv_img*
-rwxr-xr-x  1 root  admin  2063132 Feb 16 17:48 libopencv_imgproc.2.4.8.dylib*
lrwxr-xr-x  1 root  admin       29 Feb 16 17:48 libopencv_imgproc.2.4.dylib@ -> libopencv_imgproc.2.4.8.dylib
lrwxr-xr-x  1 root  admin       27 Feb 16 17:48 libopencv_imgproc.dylib@ -> libopencv_imgproc.2.4.dylib
童话 2025-01-11 21:25:03

当您没有将 OpenCV 库链接到编译的程序时,就会发生这种情况。尝试在 OpenCV Wiki 上的 Xcode 项目中使用 OpenCV 的说明,看看是否有帮助。

That happens when you don't link the OpenCV library to your compiled program. Try the instructions for using OpenCV in an Xcode project on the OpenCV Wiki and see if that helps.

吹梦到西洲 2025-01-11 21:25:03

几天前我遇到了完全相同的问题。但是,现在已经解决了。

基本上,您需要检查三件事。
1. 搜索路径设置是否正确?
在项目的“构建设置”标签上,您需要将标头搜索路径和库搜索路径设置为标头和库的目录。我使用MacPort安装了opencv 2.4,所以路径是/opt/local/include & /opt/local/lib

  1. 您是否手动添加了库?
    建设阶段 -->将 Binary 与 Library 标签链接起来,您需要将需要使用的 opencv dylib 添加到此位置。

  2. 你选择了GCC编译器吗?
    Xcode 中的默认编译器是 Apple LLVM 编译器,它使用 c++11 标准。由于opencv 2.4不兼容该标准,因此需要将编译器切换为GCC。您可以在 Building Settings 标签下更改它

希望我的经验可以帮助您解决问题;)

i got the exactly same problem few days ago. but, it's fixed now.

Basically, you need to check three things.
1. Have you set the search path correctly?
on your project "building Settings" tag, you need to set the Header Search Path and Library Search Path to the header's and lib's directory. I installed opencv 2.4 by using MacPort, so the path is /opt/local/include & /opt/local/lib

  1. Have you manually add the library?
    Under the Building Phases --> Link Binary with Library tag, you need to add those opencv dylib that you need to use to this place.

  2. Have you choose the GCC compiler?
    the default compiler in your Xcode is Apple LLVM compiler, which use c++11 standard. Since opencv 2.4 is not compatible with this standard, you need to switch the compiler to GCC. You can change it under the Building Setting tag

Hope my experience can help you fix the problem ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文