与OpenCV 3.0链接时出现“无法解析的外部符号"错误 [英] 'unresolved external symbol' error when linking with OpenCV 3.0

查看:244
本文介绍了与OpenCV 3.0链接时出现“无法解析的外部符号"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从源代码构建了OpenCV 3.0.并使用contrib repo来添加一些额外的模块.然后,我手动设置VS2013项目以使用生成的lib文件.

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.

我的代码目前很简单:

#include "opencv2\core\core.hpp"
#include "opencv2\imgcodecs\imgcodecs.hpp"

int _tmain(int argc, _TCHAR* argv[])
{
    cv::Mat image = cv::imread("img.jpg");
    return 0;
}

但是在VS 2013社区版本中,它给了我这些错误:

But it gave me these errors when in VS 2013 community version:

我看到类似线程,他们说这是由x86/x64问题引起的.但是我的项目已经是x86.我构建的OpenCV也针对x86(请参见下文).可能是什么原因?

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?

OpenCV 3.0 INSTALL项目生成以下lib目录:

The OpenCV 3.0 INSTALL project generates the following lib directory:

所以它确实是x86一个.

我的lib路径配置为上述路径:

My lib path is configured to the above path:

然后我添加了所有*d.lib文件.

And I added all the *d.lib files.

下面是我的VC项目的Configuration Manager

And below is my VC project's Configuration Manager

所以它确实也是x86.

哪里出问题了?

我手动搜索了fastFree()函数.它在opencv_core300d.lib文件中定义.我使用dumpbin /symbols命令检查符号.而且我发现它的名称与fastFree@cv@@YAXPAX@Z完全一样.那么为什么找不到它呢?

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?

推荐答案

在Windows(经过Windows 8.1测试)和Visual Studio中,对于静态链接OpenCV的C ++项目,这里有将OpenCV 3.0.0与预编译的库一起使用的步骤. (已在Visual Studio 2013中测试)运行此程序:

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 <opencv2\opencv.hpp>
using namespace cv;

int main()
{
    Mat3b img = imread("path_to_image");
    imshow("img", img);
    waitKey();
    return 0;
}

  1. http://opencv.org/downloads.html
  2. 下载
  3. 提取
  4. 我们将包含以下内容的目录称为OPENCV_DIR:
    • 构建
  1. Download from http://opencv.org/downloads.html
  2. Extract
  3. Let's call OPENCV_DIR the dir containing:
    • build
    • source
  • 新项目-> Visual C ++->空项目
  • 配置属性-> VC ++目录
  • 包含目录:添加OPENCV_DIR \ build \ include
  • 库目录:添加OPENCV_DIR \ build \ x86 \ vc12 \ staticlib

添加所需的库(以下对于此简单示例很有用,如果需要其他功能,则应添加更多库):

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)
  • 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 ++->代码生成->运行时库

Configuration Properties -> C/C++ -> Code Generation -> Runtime Library

  • 设置为多线程调试(/MTd)

对于RELEASE构建,您需要在发布模式下执行6到9的步骤,在步骤8中添加没有尾随"d"的库,并在步骤9中添加多线程(/MT).

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.

作为奖励,我还建议为Visual Studio安装 Image Watch 扩展.对于调试Mat非常有用!

As a bonus, I also recommend to install Image Watch extension for Visual Studio. Very very useful for debugging your Mats!

这篇关于与OpenCV 3.0链接时出现“无法解析的外部符号"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆