Building OpenCV 3.2.0 with VS2015 as x86 [closed]

asked 2017-03-03 13:54:11 -0600

yrazin gravatar image

updated 2017-03-03 14:24:18 -0600

I have code written many years ago (displayvideoqt) for Win32 that I want to add opencv functions to. I did all the include, linker, and library options in VS2015, compiled from scratch using CMake, etc and no matter what I try to tweak I always get the following error just from trying to use cv::Mat (#include <opencv2\core\core.hpp>

displayvideoqt.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPAHH@Z) referenced in function "public: void __thiscall cv::Mat::release(void)" (?release@Mat@cv@@QAEXXZ)

I have found that in cv::Mat::release() CVX_ADD is defined as this cv::_interlockedExchangeAdd(int *, int) in core/system.hpp. It appears that the function is actually defined in core/operations.hpp but that the definition is not being linked to despite the fact that I have the opencv_core320d.lib in my linker.

I am using CMake, VS2015, and on Windows 10.

Any help would be much appreciated!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2017-03-10 16:12:02.615848

Comments

I don't understand "Building OpenCV 2.4.8" and "I have the opencv_core320d.lib".

displayvideoqt.obj do you build opencv with qt ?

LBerger gravatar imageLBerger ( 2017-03-03 13:59:26 -0600 )edit

The code I was given (displayvideoqt) uses qt but it's not essential for what I want to do with opencv.
I am compiling the code for OpenCV 2.4.8 from the source. As part of this of course I build opencv_core320d.lib which I then put into my property>linker sheet

yrazin gravatar imageyrazin ( 2017-03-03 14:03:01 -0600 )edit

You build opencv 3.2.0 and you cannot link your program.

check if you solution is in debug mode.

Can you move all your source code in another folder and build a basic program like this one using same solution

LBerger gravatar imageLBerger ( 2017-03-03 14:12:12 -0600 )edit

You're right - Im building OpenCV 3.2.0 - not 2.4.8 but that just was me being confused - I will revise the question - even the simplest code (below) fails

#include <iostream>
#include <opencv2\core\core.hpp>

using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
    cv::Mat a;
    return 0;
}
yrazin gravatar imageyrazin ( 2017-03-03 14:23:35 -0600 )edit

With this basic code make a new folder copy source file in this folder add ths CMakeLists.txt :

cmake_minimum_required(VERSION 2.8)
PROJECT (MyOpencvProject)
find_package(OpenCV  REQUIRED)

file(GLOB MyOpencvProject_SRCS
    "*.h"
    "*.cpp")
ADD_EXECUTABLE (MyOpencvProject ${MyOpencvProject_SRCS})

if (OpenCV_FOUND)
    include_directories( ${OpenCV_INCLUDE_DIRS} )
    target_link_libraries( MyOpencvProject ${OpenCV_LIBS} )
else (OpenCV_FOUND)
message("PB->OPENCV = ${OpenCV_INCLUDE_DIRS}")
endif (OpenCV_FOUND)

then run cmake select where is the source code the new folder where to build binaries the new folder press configure selec vs 14 2015
if cmake cannot find opencv give path where you build opencv and press generate

LBerger gravatar imageLBerger ( 2017-03-03 14:34:24 -0600 )edit

Not sure I totally understood this - I put it in and then I needed to find a FindOpenCV.cmake and then I had trouble figuring out all the paths like OpenCV_DIR_ROOT and OpenCV_CORE_DIR and OpenCV_HIGHGUI_LIBRARY, etc. Any ideas where these should all point?

yrazin gravatar imageyrazin ( 2017-03-06 23:29:03 -0600 )edit

I'm agree with you I don't understand what you are doing. I think You should forget VS and use only cmake. CMake will do everything for you include path path to lib platform x86 x64.... You don't need to set environment variables too. I made a little video to explain process.

LBerger gravatar imageLBerger ( 2017-03-07 01:30:59 -0600 )edit

Your method worked for the test script but not for my actual project - I still get the same error. I'll keep working on it.

yrazin gravatar imageyrazin ( 2017-03-07 14:30:02 -0600 )edit

try to disable videoio module in opencv and check if compiler option /Oi is used in your project

LBerger gravatar imageLBerger ( 2017-03-07 14:50:51 -0600 )edit

I got it eventually - your code helped once I figured it out. Thanks!!

yrazin gravatar imageyrazin ( 2017-03-10 14:17:50 -0600 )edit