与 OpenCV 3.0 链接时出现“未解析的外部符号"错误 [英] 'unresolved external symbol' error when linking with OpenCV 3.0
问题描述
我从源代码构建 OpenCV 3.0.以及一些额外模块的 contrib repo.我手动设置了我的 VS2013 项目以使用生成的 lib 文件.
我的代码现在很简单:
#include "opencv2corecore.hpp"#include "opencv2imgcodecsimgcodecs.hpp"int _tmain(int argc, _TCHAR* argv[]){cv::Mat image = cv::imread("img.jpg");返回0;}
但是在 VS 2013 社区版中它给了我这些错误:
我看到下载
- 构建
- 来源
- 新建项目 -> Visual C++ -> 空项目
- 配置属性 -> VC++ 目录
- 包含目录:添加 OPENCV_DIRuildinclude
- 库目录:添加 OPENCV_DIRuildx86vc12staticlib
添加所需的库(以下对这个简单的例子很有用,如果你需要其他功能,你应该添加更多):
- opencv_core300d.lib
- opencv_highgui300d.lib
- opencv_imgproc300d.lib
- opencv_hal300d.lib
- opencv_imgcodecs300d.lib
- libjpegd.lib;
- libpngd.lib
- libjasperd.lib
- IlmImfd.lib
- libtiffd.lib
- libwebpd.lib
- zlibd.lib
- ippicvmt.lib
- %(AdditionalDependencies)
配置属性 -> C/C++ -> 代码生成 -> 运行时库
- 设置为多线程调试 (/MTd)
对于 RELEASE 版本,您需要在发布模式下执行从 6 到 9 的步骤,在步骤 8 中添加不带尾随d"的库,并在步骤 9 中添加多线程 (/MT).
作为奖励,我还建议为 Visual Studio 安装 Image Watch 扩展.对调试您的 Mat
非常有用!
I build the OpenCV 3.0 from source. And with the contrib repo for some extra modules. And I manually setup my VS2013 project to use the generated lib files.
My code is simple for now:
#include "opencv2corecore.hpp"
#include "opencv2imgcodecsimgcodecs.hpp"
int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat image = cv::imread("img.jpg");
return 0;
}
But it gave me these errors when in VS 2013 community version:
I see similar thread, they said it is caused by the x86/x64 issue. But My project is already x86. And the OpenCV I built is also targeting x86 (see below). What reason could it be?
ADD 1
The OpenCV 3.0 INSTALL
project generates the following lib directory:
So it is indeed a x86
one.
My lib path is configured to the above path:
And I added all the *d.lib
files.
And below is my VC project's Configuration Manager
So it is indeed x86
, too.
Where could be wrong?
ADD 2
I manually searched for the fastFree()
function. It is defined in the opencv_core300d.lib
file. I use the dumpbin /symbols
command to check the symbols. And I find its name is mangled exactly as fastFree@cv@@YAXPAX@Z
. So why it cannot be found?
Here the steps to use OpenCV 3.0.0 with precompiled libs, for a C++ project that links OpenCV statically, in Windows (tested with Windows 8.1) and Visual Studio (tested with Visual Studio 2013) to run this program:
#include <opencv2opencv.hpp>
using namespace cv;
int main()
{
Mat3b img = imread("path_to_image");
imshow("img", img);
waitKey();
return 0;
}
- Download from http://opencv.org/downloads.html
- Extract
- Let's call OPENCV_DIR the dir containing:
- build
- source
- Create an empty project:
- New Project -> Visual C++ -> Empty Project
- Add a cpp file (say Start.cpp) that will contain your main function (e.g. the snippet above)
- Configuration DEBUG
- Add include and lib directories:
- Configuration Properties -> VC++ Directories
- Include Directories: add OPENCV_DIRuildinclude
- Library Directories: add OPENCV_DIRuildx86vc12staticlib
Add required libs (the following are good for this simple example, you should add more if you need other functionalities):
- opencv_core300d.lib
- opencv_highgui300d.lib
- opencv_imgproc300d.lib
- opencv_hal300d.lib
- opencv_imgcodecs300d.lib
- libjpegd.lib;
- libpngd.lib
- libjasperd.lib
- IlmImfd.lib
- libtiffd.lib
- libwebpd.lib
- zlibd.lib
- ippicvmt.lib
- %(AdditionalDependencies)
Configuration Properties -> C/C++ -> Code Generation -> Runtime Library
- Set to Multi-threaded Debug (/MTd)
For a RELEASE build, you need to do steps from 6 to 9 in release mode, adding libs without the trailing "d" in step 8, and Multi threaded (/MT) in step 9.
- Enjoy!
As a bonus, I also recommend to install Image Watch extension for Visual Studio. Very very useful for debugging your Mat
s!
这篇关于与 OpenCV 3.0 链接时出现“未解析的外部符号"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!