我该如何解决链接错误 My Visual C++ 2008 年使用 OpenCV?
我是 OpenCV 的大佬。
我刚刚安装了 OpenCV 并制作了 C++ 程序,如下所示。
我的编译器是Visual C++ 2008。
# include "highgui.h"
void main() {
IplImage* img = cvLoadImage("C:/OpenCV/samples/cpp/tutorial_code/images/lena.png",-1);
cvNamedWindow("lena",0);
cvShowImage("lena",image);
cvWaitKey(0);
cvReleaseImage(&image);
}
但是它无法构建并出现错误消息,我无法解决这个问题。
错误信息如下。
(我的编译器是韩文版,我将错误消息翻译成英文。 而且英文很差,但你可能明白它是如何处理的。)
1>------ begin build: project: image1st,: Debug Win32 ------
1> compiling)
1>image1st.cpp
1>c:\vs2008\ccp_file\image1st\image1st.cpp(17) : warning C4700: not inetialized ‘image’ use local variable
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>linking
1>image1st.obj : error LNK2019: _cvReleaseImage External Symbol(refrence positon: _main function) not defined.
1> image1st.obj : error LNK2019: _cvWaitKey External Symbol(refrence positon: _main function)not defined.
1> image1st.obj : error LNK2019: _cvShowImage External Symbol(refrence positon: _main function)not defined.)
1> image1st.obj : error LNK2019: _cvNamedWindow External Symbol(refrence positon: _main function)not defined.)
1>image1st.obj : error LNK2019: _cvLoadImage External Symbol(refrence positon: _main function)not defined.)
1>project: warning PRJ0018 : can not find the next environment variable.
1>$(OPENCV_DIR)
1>image1st – errors: 6, warning: 1
并且我修改了Visual C++环境,修改如下。
我在“附加包含目录”条目中输入“$(OPENCV_DIR)\include”,
并在“附加依赖项”条目中包含下一个 .lib 文件作为 OpenCV 教程 2.3 版指南。
- 'opencv_core231d.lib'
- 'opencv__imgproc231d.lib'
- 'opencv__highgui231d.lib
- '
- 'opencv__ml231d.lib'
- 'opencv__video231d.lib' 'opencv__features2d231d.lib'
- 'opencv__calib3d231d.lib'
- 'opencv__objdetect231d.lib'
- 'opencv__contrib231d.lib'
- 'opencv__legacy231d.lib'
- 'opencv__flann231d.lib'
并且将 Visual C++ 环境的包含目录和库目录修改如下。
对于库:
- $(VSInstallDir)lib
- $(VSInstallDir)
- $(FrameworkSDKDir)lib
- $(WindowsSdkDir)\lib
- $(VCInstallDir)atlmfc\lib\i386
- $(VCInstallDir)atlmfc\lib
- $(VCInstallDir)lib
- C:\opencv\build \x86\vc10\lib // 修改
- C:\opencv\build\x86\vc9\lib // 修改
- C:\opencv\build\x64\vc10\lib // 修改
- C:\opencv\build\x64\vc9\lib // 修改
- C:\opencv\build\gpu\x86\lib // 修改
- C:\opencv\ build\gpu\x64\lib // 修改
为 include:
- $(VCInstallDir)atlmfc\include
- $(WindowsSdkDir)\include
- $(FrameworkSDKDir)include
- $(VCInstallDir)include
- C:\OpenCV\build\include\opencv // 修改
- C:\OpenCV\build\include\opencv2 // 修改
- C:\opencv\build\include // 修改
I am the very bignner for the OpenCV.
I’ve just install the OpenCV and make the C++ program as follow.
My compiler is visual C++ 2008.
# include "highgui.h"
void main() {
IplImage* img = cvLoadImage("C:/OpenCV/samples/cpp/tutorial_code/images/lena.png",-1);
cvNamedWindow("lena",0);
cvShowImage("lena",image);
cvWaitKey(0);
cvReleaseImage(&image);
}
But it could not be built with the error message, and I cannot solve this problem.
The error message is as follow.
(My compiler is Korean Version and I translate the error message into English.
And the English is poor, but you may understand how it was processed.)
1>------ begin build: project: image1st,: Debug Win32 ------
1> compiling)
1>image1st.cpp
1>c:\vs2008\ccp_file\image1st\image1st.cpp(17) : warning C4700: not inetialized ‘image’ use local variable
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>linking
1>image1st.obj : error LNK2019: _cvReleaseImage External Symbol(refrence positon: _main function) not defined.
1> image1st.obj : error LNK2019: _cvWaitKey External Symbol(refrence positon: _main function)not defined.
1> image1st.obj : error LNK2019: _cvShowImage External Symbol(refrence positon: _main function)not defined.)
1> image1st.obj : error LNK2019: _cvNamedWindow External Symbol(refrence positon: _main function)not defined.)
1>image1st.obj : error LNK2019: _cvLoadImage External Symbol(refrence positon: _main function)not defined.)
1>project: warning PRJ0018 : can not find the next environment variable.
1>$(OPENCV_DIR)
1>image1st – errors: 6, warning: 1
And I modified the visual c++ environment are modified as follow.
And I input “$(OPENCV_DIR)\include” in the “Additional Include Directories” entry,
and make the “Additional Dependencies” entry to include the next .lib file as the OpenCV Tutorials
Release 2.3 guides.
- ‘opencv_core231d.lib’
- ‘opencv__imgproc231d.lib’
- ‘opencv__highgui231d.lib’
- ‘opencv__ml231d.lib’
- ‘opencv__video231d.lib’
- ‘opencv__features2d231d.lib’
- ‘opencv__calib3d231d.lib’
- ‘opencv__objdetect231d.lib’
- ‘opencv__contrib231d.lib’
- ‘opencv__legacy231d.lib’
- ‘opencv__flann231d.lib’
And the include and library directories of visual c++ environment are modified as follow.
For library:
- $(VSInstallDir)lib
- $(VSInstallDir)
- $(FrameworkSDKDir)lib
- $(WindowsSdkDir)\lib
- $(VCInstallDir)atlmfc\lib\i386
- $(VCInstallDir)atlmfc\lib
- $(VCInstallDir)lib
- C:\opencv\build\x86\vc10\lib // modified
- C:\opencv\build\x86\vc9\lib // modified
- C:\opencv\build\x64\vc10\lib // modified
- C:\opencv\build\x64\vc9\lib // modified
- C:\opencv\build\gpu\x86\lib // modified
- C:\opencv\build\gpu\x64\lib // modified
For include:
- $(VCInstallDir)atlmfc\include
- $(WindowsSdkDir)\include
- $(FrameworkSDKDir)include
- $(VCInstallDir)include
- C:\OpenCV\build\include\opencv // modified
- C:\OpenCV\build\include\opencv2 // modified
- C:\opencv\build\include // modified
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的处理器似乎无法识别用户 vairble OPEN_CV
首先,确保系统\用户名正确。
为此,请转到系统属性 -->在高级菜单上 -->去环境变量-->确保您的系统变量正确,如果不正确,请使用您打开的简历库位置的路径创建一个变量。
看起来你做的一切都是正确的,
我相信你的问题是你在构建后步骤中错过了一些...
其次,你必须将 dll 文件从 openCV 库复制到项目的位置。
为此,请在项目的构建后步骤中包含适当的路径。
转到您的项目:属性...观看图片
并包含命令:
祝你好运
S
It's seems that your processor can't recognize the user vairble OPEN_CV
first, make sure that the system\user vairble is correct.
in order to do that go to system properties --> on advance menu --> to go Enviroment variables --> make sure your system variable is correct , if not please create one with the path to your open cv library location.
it's seems like you are doing everything right ,
I believe your problem is that you have missed some at the post build step ...
Second , you'll have to copy the dll files from the openCV library to the location of your project.
in order to do so , please include an appropriate path on the post build step on your project.
go to your project : properties ... watch the picture
and include the command:
Good luck
S
基本上,编译器似乎无法找到 OpenCV 库,或者无法识别正确的库。
确保所需的库(即
opencv__xxx.lib
)可以在您在库目录(C:\opencv\build\x86\vc10\lib
C:\opencv\build\x86\vc10\lib)中指定的目录中找到code> 等)此外,您应该只指定您平台的目录,即仅vc9
(因为您使用的是 VS2008)并且x86
/x64
取决于您的架构。PRJ0018
警告表示未设置OPENCV_DIR
环境变量。您可以在“扩展”选项卡上的系统属性对话框中执行此操作(通常通过右键单击“我的电脑”并选择“属性”来获得它,在 Win7/Vista 中您必须转到“扩展系统设置”) ,有一个按钮“环境变量”。但如果您已经修改了包含目录,则无论如何都可以省略“其他包含目录”设置。Basically it seems, that the compiler cannot find the OpenCV libraries or has trouble identifying the right one.
Make sure, that the needed libraries (i.e.
opencv__xxx.lib
) can be found in the directories you specified in the library directories (C:\opencv\build\x86\vc10\lib
etc.) Also, you should only specify the directories for your platform, i.e. onlyvc9
(since you're using VS2008) andx86
/x64
depending on your architecture.The
PRJ0018
warning indicates, that theOPENCV_DIR
environment variable is not set. You can do this in the System properties dialog (usually you get it by right-clicking on "My Computer" and select "Properties", in Win7/Vista you have to go to "Extended System settings") on the "Extended" Tab, there's a Button "Environment variables". But if you already modified the include directories, you can omit the "Additional include directories" setting anyway.也许它可以帮助你。
将 OpenCV 2.1 与 MS Visual Studio 结合使用
OpenCV 2.1.0 与 Visual Studio 2008
may be it can help you.
Using OpenCV 2.1 with MS Visual Studio
OpenCV 2.1.0 with Visual Studio 2008