Linker can not find OpenCV libraries when using CMake - opencv

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++.

Related

Can't link a project using cmake with OpenCV and LibTorch

I asked a similar question about linking a project with OpenCV a few days ago. I got that working, but now I've hit a very weird problem using CMake and adding LibTorch to the project.
If I only use OpenCV in the project, everything compiles, links, and runs fine.
But if I add Torch to CMakeLists.txt, I get a linker error:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
project(torchscriptie)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
find_package(Torch HINTS "/usr/local/libtorch")
message(STATUS "TORCH_LIBRARIES = ${TORCH_LIBRARIES}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_executable(torchscriptie main.cpp)
target_link_libraries( torchscriptie ${OpenCV_LIBS} )
target_link_libraries(torchscriptie "${TORCH_LIBRARIES}")
set_property(TARGET torchscriptie PROPERTY CXX_STANDARD 14)
This CMakeLists.txt file causes this error:
CMakeFiles/torchscriptie.dir/main.cpp.o: In function `main':
/code/cpp/torchscriptie/main.cpp:18: undefined reference to `cv::imread(std::string const&, int)'
/code/cpp/torchscriptie/main.cpp:24: undefined reference to `cv::namedWindow(std::string const&, int)'
/code/cpp/torchscriptie/main.cpp:25: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
collect2: error: ld returned 1 exit status
Here's the command:
/usr/bin/c++ -g -rdynamic CMakeFiles/torchscriptie.dir/main.cpp.o -o torchscriptie -Wl,-rpath,/usr/local/lib:/usr/local/libtorch/lib /usr/local/lib/libopencv_gapi.so.4.3.0 /usr/local/lib/libopencv_stitching.so.4.3.0 /usr/local/lib/libopencv_alphamat.so.4.3.0 /usr/local/lib/libopencv_aruco.so.4.3.0 /usr/local/lib/libopencv_bgsegm.so.4.3.0 /usr/local/lib/libopencv_bioinspired.so.4.3.0 /usr/local/lib/libopencv_ccalib.so.4.3.0 /usr/local/lib/libopencv_dnn_objdetect.so.4.3.0 /usr/local/lib/libopencv_dnn_superres.so.4.3.0 /usr/local/lib/libopencv_dpm.so.4.3.0 /usr/local/lib/libopencv_face.so.4.3.0 /usr/local/lib/libopencv_freetype.so.4.3.0 /usr/local/lib/libopencv_fuzzy.so.4.3.0 /usr/local/lib/libopencv_hdf.so.4.3.0 /usr/local/lib/libopencv_hfs.so.4.3.0 /usr/local/lib/libopencv_img_hash.so.4.3.0 /usr/local/lib/libopencv_intensity_transform.so.4.3.0 /usr/local/lib/libopencv_line_descriptor.so.4.3.0 /usr/local/lib/libopencv_quality.so.4.3.0 /usr/local/lib/libopencv_rapid.so.4.3.0 /usr/local/lib/libopencv_reg.so.4.3.0 /usr/local/lib/libopencv_rgbd.so.4.3.0 /usr/local/lib/libopencv_saliency.so.4.3.0 /usr/local/lib/libopencv_stereo.so.4.3.0 /usr/local/lib/libopencv_structured_light.so.4.3.0 /usr/local/lib/libopencv_superres.so.4.3.0 /usr/local/lib/libopencv_surface_matching.so.4.3.0 /usr/local/lib/libopencv_tracking.so.4.3.0 /usr/local/lib/libopencv_videostab.so.4.3.0 /usr/local/lib/libopencv_viz.so.4.3.0 /usr/local/lib/libopencv_xfeatures2d.so.4.3.0 /usr/local/lib/libopencv_xobjdetect.so.4.3.0 /usr/local/lib/libopencv_xphoto.so.4.3.0 /usr/local/libtorch/lib/libtorch.so /usr/local/libtorch/lib/libc10.so /usr/local/lib/libopencv_shape.so.4.3.0 /usr/local/lib/libopencv_highgui.so.4.3.0 /usr/local/lib/libopencv_datasets.so.4.3.0 /usr/local/lib/libopencv_plot.so.4.3.0 /usr/local/lib/libopencv_text.so.4.3.0 /usr/local/lib/libopencv_dnn.so.4.3.0 /usr/local/lib/libopencv_ml.so.4.3.0 /usr/local/lib/libopencv_phase_unwrapping.so.4.3.0 /usr/local/lib/libopencv_optflow.so.4.3.0 /usr/local/lib/libopencv_ximgproc.so.4.3.0 /usr/local/lib/libopencv_video.so.4.3.0 /usr/local/lib/libopencv_videoio.so.4.3.0 /usr/local/lib/libopencv_imgcodecs.so.4.3.0 /usr/local/lib/libopencv_objdetect.so.4.3.0 /usr/local/lib/libopencv_calib3d.so.4.3.0 /usr/local/lib/libopencv_features2d.so.4.3.0 /usr/local/lib/libopencv_flann.so.4.3.0 /usr/local/lib/libopencv_photo.so.4.3.0 /usr/local/lib/libopencv_imgproc.so.4.3.0 /usr/local/lib/libopencv_core.so.4.3.0 -Wl,--no-as-needed,/usr/local/libtorch/lib/libtorch_cpu.so -Wl,--as-needed /usr/local/libtorch/lib/libc10.so -lpthread -Wl,--no-as-needed,/usr/local/libtorch/lib/libtorch.so -Wl,--as-needed
I've tried a lot of different combination of commands, but I cannot figure our what's wrong.
When I echo the TORCH_LIBRARIES variable, it returns:
torch;torch_library;/usr/local/libtorch/lib/libc10.so
If I change the libaries, for example to torch_cpu, I'm able to link OpenCV libraries.
set(TORCH_LIBRARIES torch_cpu)
I have no idea why Torch libraries are causing link errors with OpenCV in the same project.
Any suggestions would be great.
Not sure if this fixes your problem, but I had also a few problems like yours. It is working for me with a cmake file including this:
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(MyProject)
set(CMAKE_CXX_STANDARD 14)
list(APPEND CMAKE_PREFIX_PATH "folderToLibtorch/libtorch/share/cmake")
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lm -ldl")
add_executable(MyProject ...some project files...)
target_link_libraries(MyProject ${TORCH_LIBRARIES} ${OpenCV_LIBS})
set_property(TARGET MyProject PROPERTY CXX_STANDARD 14)
So make sure list(APPEND CMAKE_PREFIX_PATH "folderToLibtorch/libtorch/share/cmake") is included, this did the trick for me. Also take care to get the right libtorch version from pytorch maybe you should use the lower link and not the "pre-..." version.
Good Luck
The problem is in the version libtorch.
Please use libtorch-cxx11-abi-shared-with-deps not libtorch-shared-with-deps. It is library conflict between libtorch and opencv.
Solution here.
There is my version of CMakeList.txt with CUDA+LIBTORCH+OPENCV support:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
SET(CUDA_HOME /usr/local/cuda)
SET(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
SET(CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda)
# SET(CUDA_CUBLAS_LIBRARIES /usr/local/cuda/lib64)
SET(CUDA_cublas_device_LIBRARY /usr/local/cuda/lib64)
# SET(CMAKE_CUDA_COMPILER_ENV_VAR /usr/local/cuda/bin/nvcc)
SET(CUDA_INCLUDE_DIRS /usr/local/cuda/include)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 50)
endif()
set(OpenCV_DIR /usr/local/lib/cmake/opencv4)
# set(OpenCV_DIR /usr/local/lib)
project(cmake_and_cuda LANGUAGES CXX CUDA)
include(CTest)
find_package(CUDA REQUIRED)
# libtorch with OpenCV support , with fixed BUG !
list(APPEND CMAKE_PREFIX_PATH ./libtorch)
find_package(Torch REQUIRED)
message(STATUS "TORCH_LIBRARIES = ${TORCH_LIBRARIES}")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV_LIBS = ${OpenCV_LIBS}")
# ADD OWN CUDA FILES FOR BUILD LIBRARY.
add_library(particles_new_lib STATIC
torch_module_plus_cuda.cu
torch_module_plus_cuda.h
)
target_compile_features(particles_new_lib PUBLIC cxx_std_14)
# We need to explicitly state that we need all CUDA files in the
# particles_new_lib library to be built with -dc as the member functions
# could be called by other libraries and executables
set_target_properties( particles_new_lib
PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
add_executable(particle_cuda_test torch_and_cuda_call.cpp)
set_property(TARGET particle_cuda_test
PROPERTY CUDA_SEPARABLE_COMPILATION ON)
# LINK ALL LIBRARIES TO TARGET particle_cuda_test
target_link_libraries(particle_cuda_test PRIVATE ${TORCH_LIBRARIES} ${OpenCV_LIBS} particles_new_lib)
# LINK LIBRARIES
target_link_libraries(particle_cuda_test PRIVATE particles_new_lib)
set_property(TARGET particle_cuda_test PROPERTY CXX_STANDARD 14)

CMake error: 'target is not built by this project' Clion Kotlin

I'm trying to load OpenCV Libraries in CMakeFile.txt but it always ends with this error:
CMake Error at CMakeLists.txt:21 (target_link_libraries):
Cannot specify link libraries for target "HelloWorld" which is not built by
this project.
I've searched on the Internet but have got no solution.
cmake_minimum_required(VERSION 3.8)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/KotlinCMakeModule)
project(untitled1 Kotlin)
find_package(OpenCV REQUIRED)
IF (OpenCV_FOUND)
include_directories(/usr/local/Cellar/opencv/3.4.0_1/include)
link_libraries(/usr/local/Cellar/opencv/3.4.0_1/lib)
ENDIF(OpenCV_FOUND)
konanc_executable(
NAME HelloWorld
SOURCES hello.kt
)
target_link_libraries(HelloWorld
/usr/local/Cellar/opencv/3.4.0_1/lib
)
Someone can help me? I think it's not working because on the use of konanc_executable instead of add_executable but I need to use Kotlin so I cannot use the add_executable command.

QT Creator links different library than command line

I have a problem I am unable to understand.
I am trying to code a project using openCV 3.1. I want to code inside the QT Creator Environment, because I'm used to that. I do not necessarily need any QT specific features at the moment, I'm working with Ubuntu 14.04.
The problem is, that whenever I try to build inside the QT Creator, it does not build with the following error, but it works if I build from the command line.
10:57:36: Starting: "/usr/bin/cmake" --build . --target all
Linking CXX executable arucoTest
CMakeFiles/arucoTest.dir/PoseEstimator.cpp.o: In function `PoseEstimator::generateMarkers(std::string, int)':
PoseEstimator.cpp:(.text+0x56): undefined reference to `cv::aruco::getPredefinedDictionary(cv::aruco::PREDEFINED_DICTIONARY_NAME)'
PoseEstimator.cpp:(.text+0xb7): undefined reference to `cv::aruco::drawMarker(cv::Ptr<cv::aruco::Dictionary>&, int, int, cv::_OutputArray const&, int)'
PoseEstimator.cpp:(.text+0x1a9): undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
CMakeFiles/arucoTest.dir/PoseEstimator.cpp.o: In function `cv::String::~String()':
PoseEstimator.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/arucoTest.dir/PoseEstimator.cpp.o: In function `cv::String::String(std::string const&)':
PoseEstimator.cpp:(.text._ZN2cv6StringC2ERKSs[_ZN2cv6StringC5ERKSs]+0x69): undefined reference to `cv::String::allocate(unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [arucoTest] Error 1
make[1]: *** [CMakeFiles/arucoTest.dir/all] Error 2
make: *** [all] Error 2
10:57:36: The process "/usr/bin/cmake" exited with code 2.
So it is some kind of linker error. When I inspect my cmake file and output, I see this:
Running "/usr/bin/cmake /XYZ/arucoTest '-GCodeBlocks - Unix Makefiles'" in /XYZ/arucoTest/testbuild.
-- OpenCV library status:
-- version: 2.4.8
-- libraries: opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_ocl;opencv_objdetect;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d
-- include path: /usr/include/opencv;/usr/include
-- Configuring done
-- Generating done
-- Build files have been written to: /XYZ/arucoTest/testbuild
As you can see, it only finds openCV 2.4.8, which I still need because of old ROS Indigo projects. However, if I execute the exact same cmake file and build from the commandline, it works perfectly:
username#pc:/XYZ/arucoTest/build$ cmake ..
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- OpenCV library status:
-- version: 3.1.0
-- libraries: opencv_xphoto;opencv_xobjdetect;opencv_ximgproc;opencv_xfeatures2d;opencv_tracking;opencv_text;opencv_surface_matching;opencv_structured_light;opencv_stereo;opencv_saliency;opencv_rgbd;opencv_reg;opencv_plot;opencv_optflow;opencv_line_descriptor;opencv_fuzzy;opencv_face;opencv_dpm;opencv_dnn;opencv_datasets;opencv_ccalib;opencv_bioinspired;opencv_bgsegm;opencv_aruco;opencv_viz;opencv_videostab;opencv_videoio;opencv_video;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_flann;opencv_features2d;opencv_core;opencv_calib3d
-- include path: /usr/local/include/opencv;/usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /XYZ/arucoTest/build
veith#roethlinLT:/XYZ/arucoTest/build$ make
Scanning dependencies of target arucoTest
[100%] Building CXX object CMakeFiles/arucoTest.dir/PoseEstimator.cpp.o
Linking CXX executable arucoTest
[100%] Built target arucoTest
As you can see I'm building in 2 different folders, because I found that if I cmake in the same folder, it does not work, even if I remove everything in that folder and cmake again from the command line. Also notice, that it finds 2 different include paths depending on where I start the cmake from.
My makefile looks like this (not very crazy), I'm using this exact same file for both cases.
project(arucoTest)
cmake_minimum_required(VERSION 2.8)
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
set(HEADER_LIST PoseEstimator.h)
set(SRC_LIST PoseEstimator.cpp)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
Using ccmake and the QT build in inspection window, I see that the OpenCV_DIR variable is set to 2 different things: On command line:
OpenCV_DIR /usr/local/share/OpenCV
In QT Creator:
OpenCV_DIR /ust/share/OpenCV
How do I set this to automatically select the right folder inside QT Creator as well? I really have no idea what could cause this!
Thanks!
Cache variable OpenCV_DIR is set by searching with command find_package (in config mode). While search mechanism is fully deterministic (it is described in the doc), it uses some envorinment variables which may differ under your shell and in QT Creator.
Just a guess, QT Creator may set CMAKE_PREFIX_PATH environment variable to contain /usr directory, so it finds an installation under /usr before one under /usr/local.
For choose specific OpenCV installation, just set OpenCV_DIR cache variable accordingly and rerun configuration process.

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

OpenCV compilation error in eclipse

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.

Resources