LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to use CMAKE to get debug libraries for OpenCV (https://www.linuxquestions.org/questions/programming-9/how-to-use-cmake-to-get-debug-libraries-for-opencv-4175646549/)

Mantabit 01-19-2019 03:58 PM

How to use CMAKE to get debug libraries for OpenCV
 
Hello everyone

I am new to using OpenCV on Linux and I have run into the following problem: I am trying to write some first C++ applications using OpenCV. I downloaded the source code (v.3.4.5) for OpenCV from their webpage. Then I compiled the source code using CMAKE, make and make install. So far everything went okay and I can compile and run the first example:https://docs.opencv.org/3.2.0/db/df5...gcc_cmake.html

The problem is that when I try to compile the application in Debug mode using QtCreator, the same code as in the example won't work. Now I assume that is because I need to link the debug libraries for OpenCV when debugging, however, I'm not sure how I can get the debug libraries from the source code. So far I basically tried the following commands in the source-code

Code:

cmake -D WITH_QT=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install

As far as I know, the debug libraries should have the same name as the release libraries but with a "d" at the end, so for example "libopencv_core.so" should be called "libopencv_cored.so". I tried searching for "libopencv_cored.so" using:

Code:

sudo find / -name libopencv_cored.so
but such a file doesn't exist anywhere on the system so I guess my compilation does not create the required debug libraries? So my question is basically how I can compile the debug libraries from the source code?

The CMAKE code for my project currently looks like this:

Code:

cmake_minimum_required(VERSION 2.8)

project(opencv_0)
find_package(OpenCV REQUIRED)
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(opencv_0 debug ${OpenCV_LIBS})

And the C++ code looks like this:

Code:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc,char** argv)
{
    Mat image;
    image=imread("lenna.jpg",1);
    if(!image.data){
        printf("Could not read picture!\n");
        return 1;
    }
    namedWindow("Display Image",WINDOW_AUTOSIZE);
    imshow("Display Image",image);

    waitKey(0);

    return 0;
}


astrogeek 01-22-2019 04:05 PM

The cmake target_link_libraries and Transitive Usage Requirements reference pages probably have the information you are missing.

I understand just enough cmake to build projects which use it, but have not used it as the build environment for any of my own, so cannot offer much more help.

Look over the above links and you should be able to resolve your issue.

Good luck!


All times are GMT -5. The time now is 11:41 PM.