Ask Your Question
0

How to configure opencv 3.0 with codeblock 13.12 - Win7

asked 2015-06-02 15:33:43 -0600

opencvuser1234 gravatar image

I new user of openCV and I am having troubles.

I am using 'codeblocks-13.12mingw-setup.exe', opencv 3.0rc1 and window 7 64 bits.

My steps until now was: - to extract the opencv to c:\opencv - to define the environment variables OPENCV_DIR and to add Path=%OPENCV_DIR%\bin;C:\Program Files (x86)\CodeBlocks\MinGW\bin; - I downloaded pkg-config and copied it to MinGW\bin directory

Now when I compile, the code below, everything works fine:

#include <iostream>
#include <opencv2/opencv.hpp>

int main()
{
    std::cout << "OpenCV Version: " << CV_VERSION << std::endl;


    return 0;
}

But, whe I compile this one:

#include <iostream>
#include "opencv2/core.hpp"

int main() {
    cv::Mat A(1000,1000,CV_64F);
    return 0; }

I receive this result:

C:\Users\user\Documents\CodeBlock\opencv02.o:opencv02.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d)||undefined reference to cv::fastFree(void*)'| C:\Users\user\Documents\CodeBlock\opencv02.o:opencv02.cpp:(.text$_ZN2cv3Mat6createEiii[__ZN2cv3Mat6createEiii]+0xb1)||undefined reference tocv::Mat::create(int, int const*, int)'| C:\Users\user\Documents\CodeBlock\opencv02.o:opencv02.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x30)||undefined reference to __atomic_fetch_add_4'| C:\Users\user\Documents\CodeBlock\opencv02.o:opencv02.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x49)||undefined reference tocv::Mat::deallocate()'| ||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

or this one:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat image;
    image = imread("imagem.jpg", CV_LOAD_IMAGE_COLOR);

    if(! image.data )
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );
    imshow( "Display window", image );

    waitKey(0);
    return 0;
}

I receive:

C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp|| undefined reference to cv::imread(cv::String const&, int)'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp|| undefined reference to cv::namedWindow(cv::String const&, int)'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp|| undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp|| undefined reference to cv::waitKey(int)'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp:(.text$_ZN2cv6StringC1EPKc[__ZN2cv6StringC1EPKc]+0x3c)||undefined reference to cv::String::allocate(unsigned int)'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp:(.text$_ZN2cv6StringD1Ev[__ZN2cv6StringD1Ev]+0xf)||undefined reference to cv::String::deallocate()'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d)||undefined reference to cv::fastFree(void*)'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp:(.text$_ZN2cv3MataSERKS0_[__ZN2cv3MataSERKS0_]+0xf8)||undefined reference to cv::Mat::copySize(cv::Mat const&)'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x30)||undefined reference to __atomic_fetch_add_4'| C:\Users\user\Documents\CodeBlock\opencv03.o:opencv03.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x49)||undefined reference tocv::Mat::deallocate()'| ||=== Build failed: 10 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I already tried to add "pkg-config --cfalgs --libs opencv" to Settings->Compiler->Linker Settings->Other Linker Options, but it does not worked. In this case I receive this message ... (more)

edit retag flag offensive close merge delete

Comments

did you actually build the opencv libs using cmake ? there are no prebuild libs for mingw, that pkg-config could retrieve, and no, you cannot use the vs libs for mingw.

berak gravatar imageberak ( 2015-06-02 23:32:38 -0600 )edit

I definitely built the opencv libs using cmake (to get the build to work, I had to deactivate WITH_IPP from cmake configuration and fix a videoio error by commenting out add_extra_compiler_option(-werror=non-virtual-dtor) as suggested in a stack overflow post though.

Now my sample opencv test code won't build either : Undefined reference to atomic_fetch_add_4 . Any ideas most appreciated !

Using opencv3.0, code blocks, mingw, latest cmake. Thanks !

mubb gravatar imagemubb ( 2015-08-05 04:45:57 -0600 )edit

@mubb I had done what you described and got the same error. I am hunting around for an easy fix.

aware_ignoramus gravatar imageaware_ignoramus ( 2015-08-06 02:26:59 -0600 )edit

you don't seem to link to opencv_highgui opencv_core, etc.

btw, which gcc version is that ? it seems to lack __atomic_fetch _4 instructions

berak gravatar imageberak ( 2015-08-06 02:46:07 -0600 )edit

I dont know, im using latest mingw for windows32

mubb gravatar imagemubb ( 2015-08-17 07:09:12 -0600 )edit

@aware_ignoramus did you find a fix ? Just followed same process on another windows machine (this time win10, and same atomic fetch error ) its driving me crazy !

mubb gravatar imagemubb ( 2015-08-17 07:11:07 -0600 )edit

Hi, same problem here. Did Build the libs with cmake and had to fix the same errors as mubb. Using CodeBlocks 13.12, Windows 8 (64-bit), opencv 3.0, cmake 3.3.0 and the MinGW included in CodeBlocks (Could not find version) but it should be the latest because there has been no new version since 2013, right?

Could it possibly be a problem with 32/64-bit? Googling for that error led me here and on other pages not related to opencv it seemed to be a problem of that nature.

Bollo2k gravatar imageBollo2k ( 2015-09-10 09:57:38 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-12-14 00:20:17 -0600

SoumyajitPal gravatar image

In Build Options->Compiler Settings->Compiler Flags tick "i486" under CPU Architecture tuning . Worked for me.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-06-02 15:33:43 -0600

Seen: 5,329 times

Last updated: Aug 17 '15