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.
Related
I downloaded the master for mapbox-gl-native, installed needed dependencies, followed instructions, then tried to build with "cmake --build build" but I get a lot of errors.
This is the first error:
[ 8%] Building CXX object CMakeFiles/mbgl-core.dir/src/mbgl/layermanager/circle_layer_factory.cpp.o
In file included from /Users/imac/Work/GitHub/mapbox-gl-native/src/mbgl/layermanager/circle_layer_factory.cpp:1:
In file included from /Users/imac/Work/GitHub/mapbox-gl-native/include/mbgl/layermanager/circle_layer_factory.hpp:3:
In file included from /Users/imac/Work/GitHub/mapbox-gl-native/include/mbgl/layermanager/layer_factory.hpp:3:
In file included from /Users/imac/Work/GitHub/mapbox-gl-native/include/mbgl/style/layer.hpp:3:
In file included from /Users/imac/Work/GitHub/mapbox-gl-native/include/mbgl/style/conversion.hpp:3:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:504:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:175:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:642:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/utility:199:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__tuple:283:5: error: static_assert failed due to
requirement '0UL < sizeof...(_Types)' "tuple_element index out of range"
static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
^ ~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__tuple:457:43: note: in instantiation of template class
'std::__1::tuple_element<0, std::__1::__tuple_types<> >' requested here
typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:1007:10: note: in instantiation of template class
'std::__1::tuple_element<0, std::__1::tuple<> >' requested here
typename tuple_element<_Ip, tuple<_Tp...> >::type&
^
/Users/imac/Work/GitHub/mapbox-gl-native/include/mbgl/util/indexed_tuple.hpp:38:16: note: while substituting deduced template arguments into function template 'get'
[with _Ip = 0, _Tp = <>]
return std::get<TypeIndex<I, Is...>::value, Ts...>(*this);
^
/Users/imac/Work/GitHub/mapbox-gl-native/src/mbgl/layout/circle_layout.hpp:20:59: note: in instantiation of function template specialization
'mbgl::IndexedTuple<mbgl::TypeList<mbgl::style::CircleSortKey>, mbgl::TypeList<mbgl::style::PropertyValue<float> > >::get<mbgl::style::CircleSortKey>'
requested here
const bool sortFeaturesByKey = !unevaluatedLayout.get<style::CircleSortKey>().isUndefined();
^
This is the result for: "gcc --version"
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
This is the result for: "cmake . -B build"
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- The C compiler identification is AppleClang 12.0.0.12000032
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring GL-Native with OpenGL renderer backend
-- Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Checking for one of the modules 'glfw3'
-- Not building node bindings, dependencies not found. Run 'npm update'.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/imac/Work/GitHub/mapbox-gl-native/build
NOTE: I have an older version of mapbox environment (July 2019) that was perfectly compiling with XCode (compiling inside XCode) but as soon as I installed XCode 12 I started to have the same error.
I am creating an app on the nvidia jetson nano (under ubuntu 18.04 LTS) using Qt-creator. To do so I create my own library (named recolib) which uses opencv (version 3.4.6) and then in my Qt app project I include my library.
The library compiles fine, but when I tried compiling the app it reaches 100% and then I get the following error: undefined reference to `cv::xfeatures2d::SURF::create(double, int, int, bool, bool)'.
Note that the class where this function is called is part of my library "recolib".
I have build opencv with cmake, I have enabled non-free modules and gave the right path to it and opencv built and installed fine.
Moreover, the app works well on mac and on an ubuntu virtual machine.
Here are samples of the Cmakelist.txt of the app:
cmake_minimum_required(VERSION 3.0)
# Add folder where are supportive functions
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -pthread -lm")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -pthread -lm")
...
find_package(OpenCV REQUIRED)
if(OPENCV_XFEATURES2D_FOUND)
message("xfeatures2d found")
endif()
...
SET(RECOLIB_DIR "${PROJECT_SOURCE_DIR}/libs/recotracking-recolib")
include_directories("${RECOLIB_DIR}/include")
if(WIN32)
link_directories("${RECOLIB_DIR}/build/Debug")
else()
link_directories("${RECOLIB_DIR}/build/")
endif()
SET(RECOLIB_LIBRARY recolib)
include_directories(${OPENCV_INCLUDE_DIRS})
...
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
FILE(GLOB_RECURSE RES_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.qrc")
FILE(GLOB_RECURSE SRC_FILES "${SRC_FOLDER}/*.cpp")
FILE(GLOB_RECURSE UI_FILES "${SRC_FOLDER}/*.ui")
FILE(GLOB_RECURSE HDR_FILES "${HDR_FOLDER}/*.h")
link_directories(${OpenCV_LIBRARY_DIRS})
message("opencv libs: ${OpenCV_LIBRARIES}")
add_executable(${execName} ${OS_BUNDLE}# Expands to WIN32 or MACOS_BUNDLE depending on OS
${RES_FILES} ${SRC_FILES} ${UI_FILES} ${HDR_FILES} ${META_FILES_TO_INCLUDE}
)
...
# Add the Qt5 Widgets for linking
if (APPLE)
target_link_libraries(${execName}
${OpenCV_LIBRARIES}
${AppKit}
${CoreAudio}
${AudioToolbox}
Qt5::Core
Qt5::Gui
Qt5::QuickControls2
Qt5::MultimediaWidgets
Qt5::Multimedia
Qt5::MultimediaPrivate
Qt5::Widgets
Qt5::Sql
${RECOLIB_LIBRARY})
else()
target_link_libraries(${execName}
${OpenCV_LIBRARIES}
Qt5::Core
Qt5::Gui
Qt5::QuickControls2
Qt5::MultimediaWidgets
Qt5::Multimedia
#Qt5::MultimediaPrivate
Qt5::Widgets
Qt5::Sql
${RECOLIB_LIBRARY})
endif()
And the output I get executing it under Qt-creator is the following:
Running "/usr/bin/cmake -E server --pipe=/tmp/cmake-Bg9h0e/socket --experimental" in /home/bookbeo-novatech/build-recotracking-app-Desktop-Release.
Starting to parse CMake project, using: "-DCMAKE_BUILD_TYPE:STRING=Release", "-DCMAKE_CXX_COMPILER:STRING=/usr/bin/g++", "-DCMAKE_C_COMPILER:STRING=/usr/bin/gcc", "-DCMAKE_PREFIX_PATH:STRING=/usr", "-DQT_QMAKE_EXECUTABLE:STRING=/usr/lib/qt5/bin/qmake".
-std=c++11 -pthread -lm
The C compiler identification is GNU 7.4.0
The CXX compiler identification is GNU 7.4.0
Check for working C compiler: /usr/bin/gcc
Check for working C compiler: /usr/bin/gcc -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: /usr/bin/g++
Check for working CXX compiler: /usr/bin/g++ -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Looking for pthread.h
Looking for pthread.h - found
Looking for pthread_create
Looking for pthread_create - not found
Looking for pthread_create in pthreads
Looking for pthread_create in pthreads - not found
Looking for pthread_create in pthread
Looking for pthread_create in pthread - found
Found Threads: TRUE
Found CUDA: /usr/local/cuda (found suitable exact version "10.0")
Found OpenCV: /usr/local (found version "3.4.6")
xfeatures2d found
opencv libs: opencv_calib3d;opencv_core;opencv_cudaarithm;opencv_cudabgsegm;opencv_cudacodec;opencv_cudafeatures2d;opencv_cudafilters;opencv_cudaimgproc;opencv_cudalegacy;opencv_cudaobjdetect;opencv_cudaoptflow;opencv_cudastereo;opencv_cudawarping;opencv_cudev;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_cvv;opencv_datasets;opencv_dnn_objdetect;opencv_dpm;opencv_face;opencv_fuzzy;opencv_hfs;opencv_img_hash;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_reg;opencv_rgbd;opencv_saliency;opencv_stereo;opencv_structured_light;opencv_surface_matching;opencv_text;opencv_tracking;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
Configuring done
Generating done
CMake Warning:
Manually-specified variables were not used by the project:
QT_QMAKE_EXECUTABLE
CMake Project was parsed successfully.
So as you can see, except for some issues with pthread (but it seems unrelated to the main problem), the cmake configuration appears to be good. Opencv is found and xfeatures2d too.
But when I build the app, at the end of the compilation I get:
[ 94%] Building CXX object CMakeFiles/recotracking-app.dir/recotracking-app_autogen/mocs_compilation.cpp.o
[ 97%] Building CXX object CMakeFiles/recotracking-app.dir/recotracking-app_autogen/EWIEGA46WW/qrc_resources.cpp.o
[100%] Linking CXX executable recotracking-app
/home/bookbeo/recotracking-app/libs/recotracking-recolib/build/librecolib.a(PCB.cpp.o): In function `reco::PCB::load(cv::Mat const&, cv::Mat const&, cv::Mat const&, std::vector<reco::RecoPoi, std::allocator<reco::RecoPoi> >)':
CMakeFiles/recotracking-app.dir/build.make:1045: recipe for target 'recotracking-app' failed
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/recotracking-app.dir/all' failed
Makefile:83: recipe for target 'all' failed
/home/bookbeo-novatech/recotracking-app/libs/recotracking-recolib/src/PCB.cpp:47: undefined reference to `cv::xfeatures2d::SURF::create(double, int, int, bool, bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [recotracking-app] Error 1
make[1]: *** [CMakeFiles/recotracking-app.dir/all] Error 2
make: *** [all] Error 2
10:51:49: Le processus "/usr/bin/cmake" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet recotracking-app (kit : Desktop)
When executing step "CMake Build"
10:51:49: Temps écoulé : 06:59.
I already tried re-building opencv, it didn't change anything, and the module xfeatures2d seems to be found so I don't know where this error is coming from.
If you have any idea, I would really appreciate it.
Thanks in advance.
I encountered a problem when trying to build caffe with cmake (trying cmake since make constantly gives me errors but it turns out cmake is nothing better...). Below is the error message:
[ 82%] Linking CXX shared library ../../lib/libcaffe.so
/usr/bin/ld: cannot find -lopencv_dep_cudart
collect2: error: ld returned 1 exit status
src/caffe/CMakeFiles/caffe.dir/build.make:3284: recipe for target 'lib/libcaffe.so.1.0.0-rc3' failed
make[2]: *** [lib/libcaffe.so.1.0.0-rc3] Error 1
CMakeFiles/Makefile2:272: recipe for target 'src/caffe/CMakeFiles/caffe.dir/all' failed
make[1]: *** [src/caffe/CMakeFiles/caffe.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
I tried to search online but did not find much information related to the missing -lopencv_dep_cudart.
I am running Ubuntu 16.04. Both gcc and gcc++ versions are 4.9. Opencv is installed and its version is 2.4.13. Below is part of the output from cmake .. that shows the dependencies for caffe (I think I have all dependencies installed):
-- Dependencies:
-- BLAS : Yes (Atlas)
-- Boost : Yes (ver. 1.58)
-- glog : Yes
-- gflags : Yes
-- protobuf : Yes (ver. 3.0.2)
-- lmdb : Yes (ver. 0.9.17)
-- LevelDB : Yes (ver. 1.18)
-- Snappy : Yes (ver. 1.1.3)
-- OpenCV : Yes (ver. 2.4.13)
-- CUDA : Yes (ver. 8.0)
--
-- NVIDIA CUDA:
-- Target GPU(s) : Auto
-- GPU arch(s) : sm_61
-- cuDNN : Yes (ver. 5.1.5)
--
-- Python:
-- Interpreter : /usr/bin/python2.7 (ver. 2.7.12)
-- Libraries : /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
-- NumPy : /home/jack/.local/lib/python2.7/site-packages/numpy/core/include (ver 1.11.1)
--
Could someone advise? Please let me know if more information is needed. Thanks so much in advance!
I had similar issue. The solutions found in online forums (like using set(CUDA_USE_STATIC_CUDA_RUNTIME OFF) in CMakeLists.txt) did not fix my problem. But you can hack your cmake files to get past this error.
Steps
Enable the verbose in cmake using set(CMAKE_VERBOSE_MAKEFILE ON)
do a make | grep lopencv_dep_cudart
The command that performs the linking will have the string highlighted. Note down the path of the cmake file that has the search string.
Copy the command and run it in a shell in the above path but without the -lopencv_dep_cudart option. Hopefully the command will execute without error
Now run the make again.
I encountered a same problem. I find the flag -lopencv_dep_cudart in the file OpenCVModules-release.cmake which is used by Find_package(OpenCV):
OpenCVModules-release.cmake
I solved this problem by using FindPkgConfig Module of cmake to find OpenCV libs:
# firstly, add your/path/to/opencv.pc to system environment variable PKG_CONFIG_PATH
# modify the file Dependencies.cmake
find_package(PkgConfig REQUIRED)
pkg_check_modules(OpenCV REQUIRED opencv)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
list(APPEND Caffe_LINKER_LIBS opencv_core opencv_highgui opencv_imgproc)
Alternatively, you can also directly set OpenCV_INCLUDE_DIRS and OpenCV_LIBS to your OpenCV path.
I'm working on a project which uses OpenCV development libraries found on my package manager. I'm currently using two machines to work on this project, my laptop and my desktop. When I compile the code on my laptop, I have no issues. However, I'm getting a linking error on my desktop, which is strange because both machines have all corresponding libraries.
The error message complains about an undefined reference to a set of methods that should be getting linked, but cannot be found. Here's the output from cmake and make:
cmake:
malak#bigblackbox:~/Dropbox/libcardreader/release$ cmake .. && make
-- The C compiler identification is GNU 4.7.2
-- The CXX compiler identification is GNU 4.7.2
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- 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
-- Configuring done
-- Generating done
-- Build files have been written to: /home/malak/Dropbox/libcardreader/release
make:
Scanning dependencies of target test
[ 33%] Building CXX object CMakeFiles/test.dir/test.cpp.o
[ 66%] Building CXX object CMakeFiles/test.dir/libimganalyzer.cpp.o
[100%] Building CXX object CMakeFiles/test.dir/libcardreader.cpp.o
Linking CXX executable test
CMakeFiles/test.dir/libimganalyzer.cpp.o: In function `cv::MSER::~MSER()':
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0xe): undefined reference to `vtable for cv::MSER'
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0x26): undefined reference to `vtable for cv::MSER'
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0x2e): undefined reference to `VTT for cv::MSER'
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0x55): undefined reference to `cv::Algorithm::~Algorithm()'
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0x8a): undefined reference to `cv::Algorithm::~Algorithm()'
collect2: error: ld returned 1 exit status
make[2]: *** [test] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
libimganalyzer.cpp has an #include statement to reference libimganalyzer.h and here is what I reference in libimganalyzer.h:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
If I use cat to look at the contents of features2d.hpp, which is where MSER is defined, it shows up:
malak#bigblackbox:~/Dropbox/libcardreader/release$ cat /usr/include/opencv2/features2d/features2d.hpp | grep MSER
typedef struct CvMSERParams
/////// the next few params for MSER of color image
} CvMSERParams;
CVAPI(CvMSERParams) cvMSERParams( int delta CV_DEFAULT(5), int min_area CV_DEFAULT(60),
CVAPI(void) cvExtractMSER( CvArr* _img, CvArr* _mask, CvSeq** contours, CvMemStorage* storage, CvMSERParams params );
/////// The class implements MSER algorithm introduced by J. Matas.
class CV_EXPORTS_W MSER : public CvMSERParams
CV_WRAP MSER();
CV_WRAP MSER( int _delta, int _min_area, int _max_area,
//! the operator that extracts the MSERs from the image or the specific part of it
MserFeatureDetector( CvMSERParams params=cvMSERParams() );
MSER mser;
malak#bigblackbox:~/Dropbox/libcardreader/release$
and here is the output of my CMakeLists.txt file:
set( CMAKE_AUTOMOC ON )
cmake_minimum_required(VERSION 2.8)
project( test )
find_package( OpenCV REQUIRED )
add_executable( test test.cpp libimganalyzer.cpp libimganalyzer.h libcardreader.cpp libcardreader.h )
target_link_libraries( test ${OpenCV_LIBS} )
I'd like to know what it is I lack on my desktop that lets me compile this project on my laptop without a hitch.
Update: I've tried multiple scenarios in terms of cmake and make on both my laptop and desktop and here's the results if it helps any:
cmake on desktop; make on desktop: cmake is successful, make throws error above.
cmake on desktop; make on laptop: cmake is successful, make is successful. Project runs.
cmake on laptop; make on desktop: cmake is successful, make is successful. Project runs.
cmake on laptop; make on laptop: cmake is successful, make is successful. Project runs.
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++.