How to configure opencv 3.0 with codeblock 13.12 - Win7
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 to
cv::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 to
cv::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 tocv::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 tocv::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 tocv::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 to
cv::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 ...
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.
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 I had done what you described and got the same error. I am hunting around for an easy fix.
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
instructionsI dont know, im using latest mingw for windows32
@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 !
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.