未定义的符号,mac 上 opencv2.3.1 中的 cvSmooth
我是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
OpenCV 编译了许多库。如果您像我一样从 OpenCV 教程开始(我正在使用 O'Reilly 的书),您可以添加
libopencv_core.dylib
和libopencv_highgui.dylib
,它们可以正常工作直到使用cvSmooth
函数。链接器错误(未定义的符号)是“您尚未链接所有必要的库,因此我找不到您要求的例程”的代码。使用 nm 命令可以轻松找到它们,有时您可以通过提供您认为可能位于其中的库来帮助搜索:
将 libopencv_imgproc.dylib 添加到您的 Xcode 项目你应该去参加比赛了。
PS:由于针对基础库的软链接,
_cvSmooth
显示了 3 次: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
andlibopencv_highgui.dylib
which worked up until using thecvSmooth
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: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:当您没有将 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.
几天前我遇到了完全相同的问题。但是,现在已经解决了。
基本上,您需要检查三件事。
1. 搜索路径设置是否正确?
在项目的“构建设置”标签上,您需要将标头搜索路径和库搜索路径设置为标头和库的目录。我使用MacPort安装了opencv 2.4,所以路径是/opt/local/include & /opt/local/lib
您是否手动添加了库?
建设阶段 -->将 Binary 与 Library 标签链接起来,您需要将需要使用的 opencv dylib 添加到此位置。
你选择了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
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.
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 ;)