Home CMake - OpenCV - cannot find -lDisplayImage

# CMake - OpenCV - cannot find -lDisplayImage

Zaphiel
1#
Zaphiel Published in 2017-12-07 17:50:00Z
 I'm trying to build a project on C++ with opencv using Cmake. But there is an error that I couldn't able to solve. I have searched a lot but found nothing. Note: I am beginner to OpenCV. So I don't even know why this library required. Just doing same insructions with a website. Error is /usr/bin/ld: cannot find -lDisplayImage. My code: #include using namespace cv; int main() { // read image Mat img = imread("foo.jpg", CV_LOAD_IMAGE_UNCHANGED); // show it in the window imshow("Window Name",img); waitKey(); }  My CMakeLists.txt: cmake_minimum_required(VERSION 3.8) project(image_processing) find_package( OpenCV REQUIRED ) set(CMAKE_CXX_STANDARD 11) set(SOURCE_FILES main.cpp) add_executable(image_processing ${SOURCE_FILES}) target_link_libraries( image_processing DisplayImage${OpenCV_LIBS} )  My compile output: [ 50%] Linking CXX executable image_processing /usr/bin/ld: cannot find -lDisplayImage collect2: error: ld returned 1 exit status CMakeFiles/image_processing.dir/build.make:137: recipe for target 'image_processing' failed make[3]: *** [image_processing] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/image_processing.dir/all' failed make[2]: *** [CMakeFiles/image_processing.dir/all] Error 2 CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/image_processing.dir/rule' failed make[1]: *** [CMakeFiles/image_processing.dir/rule] Error 2 Makefile:118: recipe for target 'image_processing' failed make: *** [image_processing] Error 2  Output of ld -ldisplayimage --verbose command: attempt to open //usr/local/lib/x86_64-linux-gnu/libdisplayimage.so failed attempt to open //usr/local/lib/x86_64-linux-gnu/libdisplayimage.a failed attempt to open //lib/x86_64-linux-gnu/libdisplayimage.so failed attempt to open //lib/x86_64-linux-gnu/libdisplayimage.a failed attempt to open //usr/lib/x86_64-linux-gnu/libdisplayimage.so failed attempt to open //usr/lib/x86_64-linux-gnu/libdisplayimage.a failed attempt to open //usr/local/lib64/libdisplayimage.so failed attempt to open //usr/local/lib64/libdisplayimage.a failed attempt to open //lib64/libdisplayimage.so failed attempt to open //lib64/libdisplayimage.a failed attempt to open //usr/lib64/libdisplayimage.so failed attempt to open //usr/lib64/libdisplayimage.a failed attempt to open //usr/local/lib/libdisplayimage.so failed attempt to open //usr/local/lib/libdisplayimage.a failed attempt to open //lib/libdisplayimage.so failed attempt to open //lib/libdisplayimage.a failed attempt to open //usr/lib/libdisplayimage.so failed attempt to open //usr/lib/libdisplayimage.a failed attempt to open //usr/x86_64-linux-gnu/lib64/libdisplayimage.so failed attempt to open //usr/x86_64-linux-gnu/lib64/libdisplayimage.a failed attempt to open //usr/x86_64-linux-gnu/lib/libdisplayimage.so failed attempt to open //usr/x86_64-linux-gnu/lib/libdisplayimage.a failed ld: cannot find -ldisplayimage  I tried to find that library but I couldn't able to find. I checked all of my lib folders. My opencv installed on /opt/opencv/ and built on /opt/opencv/release/. Thanks for any help. I don't know anything about how to solve it.
api55
2#
api55 Reply to 2017-12-08 09:32:11Z
 This happens when you copy and paste from examples without understanding them well. The problem is in the CMakeLists.txt you have cmake_minimum_required(VERSION 3.8) project(image_processing) find_package( OpenCV REQUIRED ) set(CMAKE_CXX_STANDARD 11) set(SOURCE_FILES main.cpp) add_executable(image_processing ${SOURCE_FILES}) target_link_libraries( image_processing DisplayImage${OpenCV_LIBS} )  I will go line by line here. First it checks that you have a minimum cmake version (to make sure some of the functions afterwards are valid), then is the name of the project obviously, it can be whatever you want. Then you find OpenCV library and this sets several variables (includes, libs, etc). Then you set c++11 standard and your source files, in this case it is just 1 for THIS executable (you can put as many as you need to, the same with .h if needed). Finally the important part, add_executable which you pass 2 arguments, the name of the executable (it can be whatever) and the sourcefiles... you can even write the source file manually instead of setting them into a variable first. After that you say which libraries are going to be linked to your executable... here is where you have the error!! You have to put as first argument the same name of the executable you declare before, followed by the libraries used. When you did find_package(OpenCV REQUIRED) it set the libraries name in $(OpenCV_LIBS) variable. If you need another library you can put the name manually and it will link it while compiling it. In this case you have the name DisplayImage, and it thinks it is a library name and tries to link it, this means -lDisplayImage while compiling. This means that you remove this and it should compile :) target_link_libraries( image_processing${OpenCV_LIBS} )  Also, after finding the OpenCV package I would recommend you to do include_directories( \${OpenCV_INCLUDE_DIRS} )  This will make sure the include folder is added to the compilation. Equivalent in gcc to the -Ifolder/path option. If you have to include more folders from different libraries project, you can use this command. I hope this helps you.
 You need to login account before you can post.
Processed in 0.308343 second(s) , Gzip On .