Little new to OpenCV, i've made some stuff in Java OpenCV, but limited with this lib, i've step to C/C++ with much difficulties!
I've succeded building and running C OpenCV projects, but seeing most of tutorials running on C++ version, i'm trying to make a simple "HelloCV":
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("c:/lenna.png", CV_LOAD_IMAGE_COLOR);
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(0);
return 0;
}
I always get the following errors :
../src/mainCPP.cpp:12: undefined reference to `cv::imread(std::string const&, int)'
../src/mainCPP.cpp:14: undefined reference to `cv::namedWindow(std::string const&, int)'
../src/mainCPP.cpp:15: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
../src/mainCPP.cpp:15: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
../src/mainCPP.cpp:17: undefined reference to `cv::waitKey(int)'
src\maincpp.o: In function `ZN2cv3MatD1Ev':
C:/OpenCV_2.4.9/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
src\maincpp.o: In function `ZN2cv3Mat7releaseEv':
C:/OpenCV_2.4.9/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
I've followed about 4-5 installations tuto, but I only succed in crashing my projects!
My "working" settings :
C/C++ Build -> GCC C++ Compiler -> Includes -> Include paths (-I) : path to my include folder ( "C:\OpenCV_2.4.9\opencv\build\include" )
C/C++ Build -> GCC C++ Linker -> Libraries -> Library search path (-L) -> "C:\OpenCV_2.4.9\opencv\build\x86\vc11\lib",
I know I've put the path to the x86 instead of x64 due to lib error like : "Not compatible system architecture"...!
C/C++ Build -> GCC C++ Linker -> Libraries -> Libraries (-l) : opencv_core249, opencv_imgproc249 and highgui249 (i've tested including all libs but it's the same)
I've added the environment variable : C:\OpenCV_2.4.9\opencv\build\x86\vc11\bin (isn't it only for M$ Visual Studio?!)
Seems like openCV isn't getting installed properly. Try using Chocolatey, it can cleanly install the latest version of OpenCV on windows.
Related
I am using Codeblocks 16.01 with OpenCV 3.2.0-vc14 which is installed to C:\opencv
The compile and link search directory is set in CodeBlocks already.
I wrote an openCV example, and there's a conflict as following:
-------------- Build: Debug in try_opencv (compiler: openCL)---------------
mingw32-g++.exe -L"C:\Program Files (x86)\Intel\OpenCL_SDK\6.3\lib\x86" -LC:\opencv\build\x64\vc14\lib -LC:\opencv\build\x64\vc14\bin -o bin\Debug\try_opencv.exe obj\Debug\main.o -lOpenCL C:\opencv\build\x64\vc14\lib\opencv_world320.lib C:\opencv\build\x64\vc14\lib\opencv_world320d.lib
obj\Debug\main.o: In function `main':
D:/TheOpenCLProgrammingBook/image_process_test/try_opencv/main.cpp:9: undefined reference to `cv::imread(cv::String const&, int)'
D:/TheOpenCLProgrammingBook/image_process_test/try_opencv/main.cpp:10: undefined reference to `cv::namedWindow(cv::String const&, int)'
D:/TheOpenCLProgrammingBook/image_process_test/try_opencv/main.cpp:11: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
D:/TheOpenCLProgrammingBook/image_process_test/try_opencv/main.cpp:12: undefined reference to `cv::waitKey(int)'
obj\Debug\main.o: In function `ZN2cv6StringC1EPKc':
C:/opencv/build/include/opencv2/core/cvstd.hpp:622: undefined reference to `cv::String::allocate(unsigned int)'
obj\Debug\main.o: In function `ZN2cv6StringD1Ev':
C:/opencv/build/include/opencv2/core/cvstd.hpp:664: undefined reference to `cv::String::deallocate()'
obj\Debug\main.o: In function `ZN2cv3MatD1Ev':
C:/opencv/build/include/opencv2/core/mat.inl.hpp:592: undefined reference to `cv::fastFree(void*)'
obj\Debug\main.o: In function `ZN2cv3MataSERKS0_':
C:/opencv/build/include/opencv2/core/mat.inl.hpp:613: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
obj\Debug\main.o: In function `ZN2cv3Mat7releaseEv':
C:/opencv/build/include/opencv2/core/mat.inl.hpp:704: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
10 error(s), 0 warning(s) (0 minute(s), 0 second(s))
It's so confused. Could someone help me out?
You are attempting to link libraries, e.g.
C:\opencv\build\x64\vc14\lib\opencv_world320.lib
that have been built with the MS Visual Studio 2014 C++ compiler in a program
that you are building with a different C++ compiler, namely mingw32-g++.
That won't work. Libraries built by one C++ compiler are in general
binary incompatible with programs or libraries built with a different
one and in particular, code built with an MS C++ compiler is binary
incompatible with code built by a GCC compiler (which you are using).
In addition, it seems that you are building a 32-bit program
with mingw32-g++ - since the 32-bit TDM GCC compiler is the bundled
default compiler in Code::Blocks 16.01 - and are attempting to link
64-bit libraries with it. Even if the libraries were not made by
an incompatible compiler, you cannot link 64-bit code with 32-bit
code.
All the libraries that you link in your 32[64]-bit program must
have been built with the same compiler or at least a binary ABI compatible
compiler, and they must also be 32[64]-bit.
Start again and build OpenCV from source, for targeting mingw, 32-bit,
using your mingw32 compiler. Get the windows source in the zip archive Source code
from the GitHub OpenCV repo.
It seems as if you may already have built from source. If so, then you
built the libraries for 64-bit VC++14, not mingw32, and those libraries
are useless.
To build the libraries again and configure an OpenCV project in Code::Blocks,
follow this tutorial,
carefully.
I want to use OpenCV in Eclipse Neon for C++. Unfortunately, there are some linking errors while building the project.
I followed this tutorial and passed following steps:
Installing Eclipse Neon for C/C++ (Windows 64-bit) http ://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/neon1a
Installing MinGW (mingw-get-setup.exe, https ://sourceforge.net/projects/mingw/files/Installer/) in the folder C:\MinGW
Installing OpenCV 3.1 for Windows (http ://opencv.org/downloads.html) in the folder C:\opencv
Creating a new and empty C++ project in eclipse
Adding the includes and libaries like described in the tutorial
Adding a source file Test.cpp which does not gives any errors
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat im = imread(argc == 2 ? argv[1] : "lenna.png", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
Building the project
Building the project returns following errors:
19:00:45 **** Incremental Build of configuration Release for project OpenCV ****
Info: Internal Builder is used for build
g++ "-IC:\\opencv\\build\\include" -O3 -Wall -c -fmessage-length=0 -o Test.o "..\\Test.cpp"
g++ "-LC:\\opencv\\build\\x64\\vc12\\lib" "-LC:\\opencv\\build\\x64\\vc14\\lib" -o OpenCV.exe Test.o -lopencv_world310
Test.o:Test.cpp:(.text$_ZN2cv6StringC1EPKc[__ZN2cv6StringC1EPKc]+0x2d): undefined reference to `cv::String::allocate(unsigned int)'
Test.o:Test.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x15): undefined reference to `cv::Mat::deallocate()'
Test.o:Test.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x6d): undefined reference to `cv::fastFree(void*)'
Test.o:Test.cpp:(.text.startup+0x4f): undefined reference to `cv::imread(cv::String const&, int)'
Test.o:Test.cpp:(.text.startup+0x56): undefined reference to `cv::String::deallocate()'
Test.o:Test.cpp:(.text.startup+0xc0): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
Test.o:Test.cpp:(.text.startup+0xc7): undefined reference to `cv::String::deallocate()'
Test.o:Test.cpp:(.text.startup+0xd3): undefined reference to `cv::waitKey(int)'
Test.o:Test.cpp:(.text.startup+0x134): undefined reference to `cv::String::deallocate()'
Test.o:Test.cpp:(.text.startup+0x161): undefined reference to `cv::String::deallocate()'
collect2.exe: error: ld returned 1 exit status
19:00:45 Build Finished (took 781ms)
Where can be the error?
Thank you for helping!
I'm trying to configure my Netbeans to use OpenCV 3.0.0,
When I try to build my project I got this message:
undefined reference to `cv::putText(cv::InputOutputArray const&, cv::String const&, cv::Point, int, double, cv::Scalar_, int, int, bool)'
These are my includes:
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
and my linker config:
additional libraries ---> C:/OpenCV/release/lib
libraries ---> C:/OpenCV/release/lib/libopencv_core300.dll.a ,
C:/OpenCV/release/lib/libopencv_highgui300.dll.a
Netbeans version 8.0.2, OpenCV version 3.0.0
I've compiled my own OpenCV with cmake-gui ( mingw ).
I am trying to static link OpenCV libraries on Windows. I already built the library with BUILD_SHARED_LIBS OFF and I created a project on the Eclipse (am using MinGW by the way). C:\opencv is set as my source while C:\opencv\build\x86\mingw is set as the destination on the cmake-gui. I then executed mingw32-make and mingw32-make install on C:\opencv\build\x86\mingw.
My question is, how do I static link those libraries on the Eclipse, I tried several ways but my OpenCV application still doesn't work on computers without OpenCV installed.
Here's what I tried so far, I set
C:\opencv\build\x86\mingw\install\include as the include folder;
C:\opencv\build\x86\mingw\lib as the library path on the "Linker" and I have opencv_core246, opencv_highgui246, opencv_objdetect246 and opencv_imgproc246.
This way it seems like it still uses "dynamic linking" so I tried adding -static on the Miscellaneous option but then I got these errors:
C:\opencv\build\x86\mingw\lib\libopencv_imgproc246.a(templmatch.cpp.obj):templmatch.cpp:
(.text$_ZN2cv9crossCorrERKNS_3MatES2_RS0_NS_5Size_IiEEiNS_6Point_IiEEdi+0x1ce5):
undefined reference to `cv::dft(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
C:\opencv\build\x86\mingw\lib\libopencv_imgproc246.a(templmatch.cpp.obj):templmatch.cpp:
(.text$_ZN2cv9crossCorrERKNS_3MatES2_RS0_NS_5Size_IiEEiNS_6Point_IiEEdi+0x1dab):
undefined reference to `cv::mulSpectrums(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, bool)'
C:\opencv\build\x86\mingw\lib\libopencv_imgproc246.a(templmatch.cpp.obj):templmatch.cpp:
(.text$_ZN2cv9crossCorrERKNS_3MatES2_RS0_NS_5Size_IiEEiNS_6Point_IiEEdi+0x1ded):
undefined reference to `cv::dft(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
collect2: ld returned 1 exit status
Anyone can provide me real step-by-step to static link OpenCV library on Windows using Eclipse and MinGW?
EDIT: I found out that in VS we have to add libraries such as: libtiff.lib libpng.lib libjpeg.lib libjasper.lib IlmImf.lib zlib.lib to the Linker which I did but the problem persists. Then I heard adding Vfw32.Lib comctl32.lib solved the problem but unfortunately I guess they are VS-specific.
Adding 3rd party libraries -llibjasper -llibtiff -lopencv_lapack -lzlib -lpng -ljpeg -lpthread -lrt should solve the issue.
Try compiling a very basic OpenCV code. The order of the libraries that are linked is important while linking static libraries.
If libraryA is depend on libraryB, then libraryA must be defined before defining libraryB.
I just wrote a little program using the boost filesystem library. Now it comes with some weird linking errors.
I already tried reordering the libraries, checked compiler version used for the boost binaries (Boost 1.51.0; MinGW 4.7.1 static libraries) and my MinGW version - 4.7.1.
Has someone an idea what else the cause for this could be?
Thanks in advance.
The output of the linker was:
obj\Debug\main.o: In function `ZN5boost10filesystem6existsERKNS0_4pathE':
C:/boost_1_51_0/boost/filesystem/operations.hpp:289: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj\Debug\main.o: In function `ZN5boost10filesystem4pathC1IA15_cEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE':
C:/boost_1_51_0/boost/filesystem/path.hpp:139: undefined reference to `boost::filesystem::path::codecvt()'
obj\Debug\main.o: In function `ZN5boost10filesystem11path_traits8dispatchISbIwSt11char_traitsIwESaIwEEEEvRKSsRT_RKSt7codecvtIwciE':
C:/boost_1_51_0/boost/filesystem/path_traits.hpp:174: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string, std::allocator >&, std::codecvt const&)'
I linked to the following libraries (set in Code::Blocks build options):
...\boost_1_51_0\stage\lib\libboost_system-mgw47-mt-d-1_51.a
...\boost_1_51_0\stage\lib\libboost_filesystem-mgw47-mt-d-1_51.a
The source Code (the interesting parts, i.e. the parts using boost):
//...
#define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem.hpp>
//...
int main()
{
boost::filesystem::path p("./file.txt");
if(boost::filesystem::exists(p)) cout
//...
}
//...