1

I'm running the basic OpenCV example with OpenCV3.0.0 dev:

project(ImageDenoise) cmake_minimum_required(VERSION 2.8) aux_source_directory(. SRC_LIST) find_package(OpenCV REQUIRED) include_directories( ${OpenCV_INCLUDE_DIRS} ) add_executable(${PROJECT_NAME} ${SRC_LIST}) target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) MESSAGE(${OpenCV_LIBS}) MESSAGE(${OpenCV_INCLUDE_DIRS}) 

Source code:

#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> using namespace cv; using namespace std; int main(int argc, char* argv[] ) { if ( argc != 2 ) { printf("usage: DisplayImage.out <Image_Path>\n"); return -1; } Mat image; image = imread( argv[1], IMREAD_COLOR ); if ( !image.data ) { printf("No image data \n"); return -1; } namedWindow("Display Image", WINDOW_AUTOSIZE ); imshow("Display Image", image); waitKey(0); return 0; } 

When I import this project into QtCreator, I got the following linking errors when building project:

[100%] Building CXX object CMakeFiles/ImageDenoise.dir/main.cpp.o Linking CXX executable ImageDenoise CMakeFiles/ImageDenoise.dir/main.cpp.o: In function `main': main.cpp:(.text+0x7c): undefined reference to `cv::imread(cv::String const&, int)' main.cpp:(.text+0xf5): undefined reference to `cv::namedWindow(cv::String const&, int)' main.cpp:(.text+0x144): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)' 

However when I run cmake from command line and using make, then it works perfectly. What is the reason behind this?

dzung@Cronus:~/kSVD/build$ make Scanning dependencies of target ImageDenoise [100%] Building CXX object CMakeFiles/ImageDenoise.dir/main.cpp.o Linking CXX executable ImageDenoise [100%] Built target ImageDenoise dzung@Cronus:~/kSVD/build$ ls CMakeCache.txt CMakeFiles cmake_install.cmake ImageDenoise Makefile dzung@Cronus:~/kSVD/build$ ./ImageDenoise usage: DisplayImage.out <Image_Path> 
2
  • By default, the linker scans the list of libraries only once -- so dependencies matter (which means the order-of-specification) matters. I'm guessing that on one context the order of libs emitted to the linker is different. "Why?" would be the next question, can't help there...:) Commented Feb 27, 2014 at 1:34
  • try to use make VERBOSE=1 to get the actual link command Commented Feb 27, 2014 at 4:34

1 Answer 1

1

I had exactly the same issue. I think this is some sort of a Qt-creator bug.

I solved this by:

  1. Remove everything except *.cpp and CMakeLists.txt in the project folder.
  2. Before creating anything with Qt-creator do: cmake . && make
  3. Now open existing project in Qt-creator.
  4. Now you can run cmake/compile/run etc just fine.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.