OpenCV compilation error in eclipse - opencv

I have been coding in python before and included the library of openCV without any problem. Now, I want to code in C++ so I downloaded eclipse and openCV libraries and included their path in the includes from eclipse ..
I have simple example of openCV and I am trying to run it, but I get this error -->
**** Build of configuration Debug for project Example ****
make all
Building file: ../Test.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Test.d" -MT"Test.d" -o "Test.o" "../Test.cpp"
Finished building: ../Test.cpp
Building target: Example
Invoking: GCC C++ Linker
g++ -o "Example" ./Test.o
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/../../../crt1.o: In function _start':
(.text+0x20): undefined reference tomain'
./Test.o: In function gh::main()':
/home/shamma/workspace/Example/Debug/../Test.cpp:16: undefined reference tocvCreateImage'
/home/shamma/workspace/Example/Debug/../Test.cpp:21: undefined reference to cvNamedWindow'
/home/shamma/workspace/Example/Debug/../Test.cpp:22: undefined reference tocvShowImage'
/home/shamma/workspace/Example/Debug/../Test.cpp:23: undefined reference to cvWaitKey'
/home/shamma/workspace/Example/Debug/../Test.cpp:24: undefined reference tocvDestroyWindow'
/home/shamma/workspace/Example/Debug/../Test.cpp:25: undefined reference to `cvReleaseImage'
collect2: ld returned 1 exit status
make: * [Example] Error 1enter code here
any idea what might be the cause of the problem, I have tried lots of things without use
thanks in advance

It seems you have not properly configured OpenCV libraries. I recommend you to follow the OpenCV tutorial to start using it with Eclipse.

In eclipse go to project->properties->settings and under GCC C++ linker-> libraries and assuming you're just testing, add "opencv_core" and "opencv_highgui" there are many more and for each library you need to manually include them so that eclipse can tell the compiler to link these libraries when you run your program.
Also as a note generally "cvE______" is opencv for C where as for C++ it would be cv::E____ , its really confusing that sometime you can get away with both, but not always, so stick the the function in the namespace without cv prefixes.

Related

I'm getting an error "Undefined symbols for architecture x86_64" and can't find the error in compilation

This is what my files look like
My main function is here
I compiled it using the following command:
g++ -std=c++17 main.cpp linkedList.cpp -o main
on MacOS 10.14 using the latest gcc compiler as of 2018.
It looks like the definitions for your template are not visible to the compiler when it is instantiated. You need to move the definitions from linkedList.cpp into the header file, linkedList.hpp.
(Note that C++17 support is still experimental in GCC.)

Using LAPACK with MINGW64

I am trying to incorporate LAPACK into a program I am trying to compile. I am currently using the msys2 toolchain with the MINGW64 gfortran compiler. I used the following process to obtain LAPACK:
To get BLAS and LAPACK together
In Msys2 64 bit environment type in:
Pacman –S mingw-w64-x86_64-cmake #gets cmake
Pacman –S git #gets git
Git clone https://github.com/msys2/MINGW-packages.git
Cd MINGW-packages/mingw-w64-lapack
Then navigate to ~/MINGW-packages/mingw-w64-lapack and open the file called PKGBUILD. Do a find and replace all from ‘RESPOSE’ to ‘RESPONSE’. Save the file and exit the text editor.
In the msys environment, type:
Makepkg-mingw
Pacman –U mingw-w64-x86_64-lapack*.pkg.tar.gz
BLAS and LAPACK are now installed.
To test lapack, do the following.
> cd ~
> wget http://www.math.ucla.edu/~wotaoyin/software/lapack_test.cpp # download
> g++ lapack_test.cpp -llapack -o lapack_test # build
> ./lapack_test # run
I then attempt to compile the program using LAPACK. My program only calls sgetrf and sgetrs. However, when I compile I receive the following errors:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrf.f.obj):(.text+0x43a): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrf.f.obj):(.text+0x524): undefined reference to `sgemm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x159): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x1c5): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x340): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x3ac): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x1c3): undefined reference to `isamax_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x212): undefined reference to `sswap_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x36c): undefined reference to `sger_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x3ca): undefined reference to `sscal_'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile.all:20: avl] Error 1
What am I missing in linking liblapack.a?
My command is:
gfortran -m64 -o avl avl.o aoper.o amode.o amass.o asetup.o amake.o ainput.o
aoutput.o aero.o atrim.o atpforc.o aic.o cdcl.o airutil.o autil.o aplotvl.o aplo
ttp.o aplotmd.o limits.o pltops.o hidden.o plsubs.o userio.o plutil.o arrow3d.o
getvm.o matrix.o spline.o sgutil.o second.o -static ../plotlib/libPlt_mingwSP.a
../eispack/libeispack.a -lgdi32 -luser32 -lblas -llapack
I wanted to answer my own question as I believe I found the error.
First, it looks like these calls are related to BLAS. So I needed to add -lblas to compile call. However, I initially tried this to no effect and then called -lblas AFTER the -llapack call and it worked.
Here is another solution. Get the code from https://www.gnu.org/software/gcc/testing/testing-lapack.html. Download by clicking on the link lapack.tgz. The make.inc file is already setup (you may have to rename it), so all you have to do is run make.
I went down several blind alleys before getting to this point. I tried them in google order.
http://icl.cs.utk.edu/lapack-for-windows/lapack/#libraries gave me four files which are not compatible with gfortran. Maybe I missread the webpage, but at any rate, if the compatible libraries are there, I didn't find them.
https://packages.msys2.org/package/mingw-w64-x86_64-lapack - downloading and unpacking the tar file gives files which don't work with gfortran.
http://www.netlib.org/lapack/ - download and unpack lapack-3.9.0.tar.gz. This is designed to be made on a wide variety of systems, but doesn’t include mingw gfortran. The make files and other scripts are more complicated than I wanted to tackle. One solution is given at https://gcc.gnu.org/wiki/LAPACK%20on%20Windows, but it is 8 years old and would have to be updated.
You know, it is no wonder everyone has abandoned Fortran when it is this difficult do use these standard libraries. The same stuff is built into Python, Matlab or Octave

Library not found for -llib. (clang: error: linker command failed with exit code 1 (use -v to see invocation))

I am working on a project that was previously done and uploaded on app store.When I run this app in Xcode 5.0 it is working fine but when I run this on Xcode Version 5.1.1 (5B1008) I am getting Linker error on both device and simulator.
Error Message- Library not found for -llib. (clang: error: linker command failed with exit code 1 (use -v to see invocation)).
I have searched a lot but I didn't get any thread about Library not found for -llib error. Is there anything I have to change in build settings to resolve this?
Look at the linker command line in detail for the -L options being used:
Then use Terminal or Finder to see if your libXXX.a file exists in those directories. If the library exists elsewhere then you need to configure your Library Search Paths:
However there several details which you have not provided in your question when using a library within an app:
Is the library built as part of the Xcode project/workspace (as in the first image)?
Is the library supplied by a third-party with binary (.a) and header files (as in the second image)?
TL;DR: I ran make in the wrong directory so the paths were messed up.
Problem:
>make
linking ../build/release/yubikey-personalization-gui
/usr/x86_64-suse-linux/bin/ld: cannot find -llib
...
I ran into this when compiling the Yubikey Personalisation Tool. I tracked down the -llib call in my Makefile which looked like this:
...
LINK = #echo linking $# && g++
...
LIBS = $(SUBLIBS) -L/usr/lib64 -L../lib/release -llib -lyubikey -lykpers-1 -lQtGui -L/usr/lib64 -L/usr/X11R6/lib -lQtCore -lpthread
...
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
So it was setting a variable called LINK which would print "linking" and then call g++, which is the compiler.
Then it set the var LIBS which would hold the ominous -llib.
Then it composes and runs the command $(LINK) ... $(LIBS).
Which runs g++ with the parameter -llib.
And what does that do? Turns out -l<something> is telling the compiler to use the something-library. So it asks for the library called lib here. Which is strangely generic. I figured out that the sources came with a directory called lib/, which was at ../lib.
So starting make from a directory higher up fixed it.
You should remove libstdc++ from other linker flags in your xcode project
https://stackoverflow.com/a/53103383/1344237

Linker can not find OpenCV libraries when using CMake

I have a copy of OpenCV2.4.0 installed in /usr/local/lib
My program compiled properly but when the linker is evoked, it gave errors such as:
/home/zhouw/moos-ivp-zhouw/trunk/src/pATRTest/mst.cpp:661: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat const&)'
CMakeFiles/pATR.dir/mst.cpp.o:/home/zhouw/moos-ivp-zhouw/trunk/src/pATRTest/mst.cpp:675: more undefined references to `cv::_OutputArray::_OutputArray(cv::Mat const&)'
collect2: ld returned 1 exit status
make[2]: *** [../bin/pATR] Error 1
make[1]: *** [src/pATRTest/CMakeFiles/pATR.dir/all] Error 2
make: *** [all] Error 2
The strange thing is my program uses opencv intensively, if CMake has trouble finding the libraries, it should have complained a lot more undefined references than jsut a few.
I tried adding
LINK_DIRECTORIES("/usr/local/lib") in my cmake file but it didn't help.
There's another library called POCO is also installed under /usr/local/lib. My program also links to the POCO libraries, but CMake seems having no trouble finding them.
If I manually link with -L/usr/local/lib, it would link properly without error.
The CMakeLists.txt looks like this
PROJECT(pATR)
#what files are needed?
SET(SRCS
spline.hpp
utils.hpp utils.cpp
mst.hpp mst.cpp
cluster.hpp cluster.cpp
target.hpp target.cpp
detector.hpp detector.cpp
classifier.hpp classifier.cpp
atr.hpp atr.cpp
MOOSAtr.h MOOSAtr.cpp
main.cpp
)
ADD_EXECUTABLE(pATR ${SRCS})
# indicate how to link
#LINK_DIRECTORIES("/usr/local/lib")
TARGET_LINK_LIBRARIES(pATR opencv_core opencv_highgui opencv_imgproc MOOS)
INSTALL(TARGETS
pATR
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)
Any idea what's going on? Many thanks!
If you have CMake 2.8, I recommend using find_package(OpenCV) to load the libraries.
There is an example at http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html
The CMake file:
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
You're after:
find_package(OPENCV COMPONENTS core imgproc highgui REQUIRED)
From the docs:
Packages with components
Some libraries are not monolithic, but come with one or more dependent
libraries or components. A notable example for this is the Qt library,
which ships (among others) with the components QtOpenGL and QtXml. To
use both of these components, use the following the find_package
command:
find_package(Qt COMPONENTS QtOpenGL QtXml REQUIRED)
also, for more info you may check out the following link.
https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-To-Find-Libraries
I am not sure if it makes sense that CMake can't find the linking libraries. CMake finds your dependencies and generates the Makefile, but it doesn't actually compile and link for you.
Your error are not from CMake, right? They are from make.
I always link manually with this
g++ -o myopencvapp `pkg-config --cflags --libs opencv` myopencvapp.cpp`
when invoking g++.

OpenCV build error

If this is not out of place here, would like to know about the source and fix for an error I get when I am building OpenCV under Cygwin (On Windows 7 64 bit).
I have Cygwin installed with MingW- pthread pacgae installed in that cygwin installation.
I have downloaded OpenCV ver. 2.3.1 source package.
EDIT:
After some tweaks, and changes to build process OpenCV builds fine now.
But when I compile a simple test openCV code(C source code), as below it gives lot of linker errors of undefined references to many basic openCV functions. I tried setting LD_LIBRARY_PATH correctly but still errors persit:
cc -L/usr/local/lib -I/usr/local/include/opencv2 -/usr/local/include/opencv -lop encv_imgproc -lopencv_highgui -lopencv_video -lopencv_calib3d test1.c -o test_op encv
cc: unrecognized option '-/usr/local/include/opencv'
/tmp/ccfEqFK0.o:test1.c:(.text+0x9dd): undefined reference to `_cvFree_'
/tmp/ccfEqFK0.o:test1.c:(.text+0xa4e): undefined reference to `_cvFree_'
/tmp/ccfEqFK0.o:test1.c:(.text+0xb44): undefined reference to `_cvGetRows'
/tmp/ccfEqFK0.o:test1.c:(.text+0xb6f): undefined reference to `_cvGetCols'
/tmp/ccfEqFK0.o:test1.c:(.text+0xb82): undefined reference to `_cvReleaseMat'
/tmp/ccfEqFK0.o:test1.c:(.text+0xcd2): undefined reference to `_cvAddS'
/tmp/ccfEqFK0.o:test1.c:(.text+0x1137): undefined reference to `_cvRead'
/tmp/ccfEqFK0.o:test1.c:(.text+0x11e1): undefined reference to `_cvLoadImage'
/tmp/ccfEqFK0.o:test1.c:(.text+0x129d): undefined reference to `_cvCreateImage'
/tmp/ccfEqFK0.o:test1.c:(.text+0x12dd): undefined reference to `_cvResize'
/tmp/ccfEqFK0.o:test1.c:(.text+0x12f1): undefined reference to `_cvNamedWindow'
/tmp/ccfEqFK0.o:test1.c:(.text+0x1305): undefined reference to `_cvNamedWindow'
'
/tmp/ccfEqFK0.o:test1.c:(.text+0x13ad): undefined reference to `_cvDestroyWindow
... ... Many more undefined references.
'
collect2: ld returned 1 exit status
Makefile:10: recipe for target `test_opencv' failed
make: *** [test_opencv] Error 1
EDIT
Below message is still there, but it is not an error but a message during build process.
*Then while building OpenCV under cygwin, when I do make , it gives a error message
c++: unrecognized option '-pthread'
[ 36%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_sunras.o*
and for many other files i see the same error c++: unrecognized option '-pthread'
I would like to know if anyone has experience in building openCV under Cygwin , how to get OpenCV going under cygwin? . Now I know there is windows setup for OpenCV but that is not what is an option to me.
Your cmd line arguments has a few problems. It seems that it was not fully pasted in your question (some indentation problems suggests so).
One obvious mistake can be easily identified since CC is telling you about it: cc: unrecognized option '-/usr/local/include/opencv':
When adding headers directories in the command line, you must specify each of them with -I. Notice how you failed to do so with: -/usr/local/include/opencv. It should be -I/usr/local/include/opencv
You also seem to be missing -lopencv_core in the cmd-line
In the future, use pkg-config (if its properly configured) to help you include opencv headers and libraries:
cc test.c -o test_op `pkg-config --cflags --libs opencv` -lop
Thanks for pointers:
What I found was the problem was as follows:
In my Makefile of my openCV test app I was linking with the import libraries (*.a). Which was the problem.
Problematic Makefile was linking against files
-l:/usr/local/lib/libopencv_core.dll.a ...etc...
I changed that to link with actual dll libs, then it worked(linked) fine, w/o any errors as above.
Changes Makefile looks:
LIBS = -l:/usr/local/bin/cygopencv_core-2.3.dll -l:/usr/local/bin/cygopencv_imgproc-2.3.dll -l:/usr/local/bin/cygopencv_highgui-2.3.dll -l:/usr/local/bin/cygopencv_video-2.3.dll -l:/usr/local/bin/cygopencv_calib3d-2.3.dll

Resources