Ask Your Question
0

OpenCV 2.4.9, Visual Studio 10, the infamous LNK1104 error...

asked 2014-06-30 16:53:44 -0600

WebMaka gravatar image

Greetings!

I'm checking out OpenCV as a possible solution to my needs for an optical ranging/orientation system, and have run into installation issues with OpenCV 2.4.9 on Visual Studio 2010 Professional. I don't generally have issues with setting up new development environments - I have toolchains for Atmel and Mircochip microcontrollers, SDKs for various platforms, etc. etc. etc. - but this is giving me fits.

I suspect I'm missing something stupidly simple but am just not seeing what it is...

My development environment is Visual Studio 2010 Pro SP1 on Windows 7 Ultimate x64 SP1. I get either LNK1104 (cannot open file) or LNK1107 (invalid/corrupt file) errors trying to compile a simple test program with OpenCV. My research on the 1104 error suggests a file path problem, and 1107 suggests the compiler is trying to load a DLL as a library.

What I've done to set up:

  1. My OpenCV root is:

    E:\Development\Development Tools\OpenCV

  2. My PATH environment variable is set to:

    %SystemRoot%\system32;%SystemRoot%;E:\Development\Development Tools\OpenCV\build\x64\vc10\bin;

  3. I'm working in debug/x64 mode in VS2010. All settings are relative to Active(Debug) config on Active(x64) platform in the project's properties.

  4. Project Properties > VC++ Directories > Include Directories reads:

    E:\Development\Development Tools\OpenCV\build\include

  5. Project Properties > VC++ Directories > Library Directories reads:

    E:\Development\Development Tools\OpenCV\build\x64\vc10\lib

  6. Project Properties > C/C++ > General > Additional Include Directories reads:

    E:\Development\Development Tools\OpenCV\build\include E:\Development\Development Tools\OpenCV\build\include\opencv E:\Development\Development Tools\OpenCV\build\include\opencv2

  7. Project Properties > Linker > General > Additional Library Directories reads:

    E:\Development\Development Tools\OpenCV\build\x64\vc10\lib

  8. Project Properties > Linker > Input > Additional Dependencies reads:

    opencv_core249d.dll

My simple "make sure it's working" application consists of a really simple file:

#include <opencv\cv.h>

using namespace cv;

int Main()
{
    return 0;
}

Compile fails with error LNK1104: cannot open file 'opencv_core249d.dll'. If I change the Additional Dependencies entry for that file to include a full path to the file, compile fails with error LNK1107: invalid or corrupt file: cannot read at 0x310, affecting opencv_core249d.dll.

I've gone all over the Internet trying to figure out why I'm having this issue, since as near as I can tell I have VS2010 pointed in the right direction in every place it's required, and I've rebooted a good dozen times thus far in case it's a "rebooting Windows fixes it" type of problem (read: environment vars not updating), but to no avail.

Any ideas on what I'm missing or where I should look next?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-06-30 21:23:38 -0600

unxnut gravatar image

Additional dependencies should get lib and not dll. So, change your additional dependencies to: opencv_core249d.lib.

edit flag offensive delete link more

Comments

Tried setting Additional Dependencies to point to the library file with opencv_core249d.lib, both with and without a full path. Both failed with 1104.

EDIT: Also tried moving the OpenCV directory root over to a drive root so it's not inside a path that contains spaces, as I've found a few complaints of inconsistent handling of spaces in file paths on some installs of VS2010. This also made no difference - still getting 1104s no matter what I do.

What annoys me about this is that, as near as I can tell from the plethora of people discussing setting up OpenCV with VS2010, I have every relevant setting correct and it -still- won't work. I'm missing something that's important enough to stop the whole process but it's subtle enough that it's not catching my attention.

WebMaka gravatar imageWebMaka ( 2014-07-01 21:05:00 -0600 )edit

Can you change your include statement to #include &lt;opencv2/core/core.hpp&gt;? cv.h is the legacy OpenCV while you are using the namespace from the C++ version.

unxnut gravatar imageunxnut ( 2014-07-01 23:10:02 -0600 )edit

Tried that, and still getting 1104s. Just double-checked my path environment variable and it does show the correct full path to the DLLs. I am at a loss.

WebMaka gravatar imageWebMaka ( 2014-07-04 19:31:38 -0600 )edit

One more thing. Make sure that both your OpenCV as well as the application are compiled with either 64-bit or 32-bit. You cannot mix those two.

unxnut gravatar imageunxnut ( 2014-07-04 23:32:45 -0600 )edit

Indeed - I'm using the x64 libraries and DLLs and x64/debug for the IDE's mode.

WebMaka gravatar imageWebMaka ( 2014-07-06 13:53:21 -0600 )edit
1

Got it working, but it was a convoluted process. I had to do a full compile from sources, and when that finished I had to instruct VS2010 to use <OpenCV Root>\build\include in Include Directories, <OpenCV Root>\build\lib\Debug in Library Directories. THEN it was able to "see."

WebMaka gravatar imageWebMaka ( 2014-07-06 17:13:42 -0600 )edit

Question Tools

Stats

Asked: 2014-06-30 16:53:44 -0600

Seen: 2,696 times

Last updated: Jun 30 '14