简体   繁体   中英

How to fix the fatal error LNK1112 and LNK1120 in VS 2010

I start using OpenCV 2.3 in VS 2010 so there are a lot of things I don't know. I installed OpenCV by following the guide here: http://siddhantahuja.wordpress.com/2011/07/18/getting-started-with-opencv-2-3-in-microsoft-visual-studio-2010-in-windows-7-64-bit/

but I couldn't chose "Create new project platforms" in step 4 to create a project. And when I inserted the code, I had many problems.

1>opencv_highgui230d.lib(opencv_highgui230d.dll) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'

If I erase waitKey() , I'll have that error:

1>C:\\Users\\Gia Linh\\Documents\\Visual Studio 2010\\Projects\\Testopencv\\Debug\\Testopencv.exe : fatal error LNK1120: 6 unresolved externals

I don't know how to fix it. Please, help me. Thank you a lot!

#include "stdafx.h"
#include<stdio.h>
#include "cv.h"
#include "highgui.h"
using namespace cv;

int _tmain(int argc, _TCHAR* argv[])
{
    char* imagename = "lena.jpg";
    Mat img = imread(imagename);
    if(img.empty()){
    fprintf(stderr,"can't load image %s\n",imagename); 
        return -1;
    }
    if(!img.data) 
        return -1;
    namedWindow("show an image",CV_WINDOW_AUTOSIZE);
    imshow("show an img",img);
    waitKey();
    return 0;
}

It seems that you linked to x64 dll's and lib's of opencv and trying to run it under x86 configuration of Visual Studio! Try adding another path to the environment variables to "opencvDIR/build/x86/vc10/bin" and check all the paths in: (Im assuming you are trying to run an x86 project)

Project properties > Configuration Properties >Linker > General> Additional Library Directories: should be something like: opencvDIR\\build\\x86\\vc10\\lib.

and

Project properties > Configuration Properties >Linker > Input> Additional Dependencies: should contain the appropriate lib file name, if you are in debug mode they should be with a "d" at the end of the file name(stands for debug) and without it if you are in release mode.

I would allso suggest creating a property sheet for opencv rather then linking in the project settings!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM