Ask Your Question
0

Compile Error after Install on Ubuntu with CUDA

asked 2020-05-15 07:40:03 -0600

sandro4912 gravatar image

I installed OpenCV on Ubuntu with CUDA with this guide:

https://gist.github.com/raulqf/f42c71...

However when I try to compile the program:

#include <iostream>
#include <ctime>
#include <cmath>
#include "bits/time.h"

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>

#include <opencv2/core/cuda.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudaimgproc.hpp>

#define TestCUDA true

int main() {
    std::clock_t begin = std::clock();

        try {
            cv::String filename = "/home/raul/Pictures/Screenshot_20170317_105454.png";
            cv::Mat srcHost = cv::imread(filename, cv::IMREAD_GRAYSCALE);

            for(int i=0; i<1000; i++) {
                if(TestCUDA) {
                    cv::cuda::GpuMat dst, src;
                    src.upload(srcHost);

                    //cv::cuda::threshold(src,dst,128.0,255.0, CV_THRESH_BINARY);
                    cv::cuda::bilateralFilter(src,dst,3,1,1);

                    cv::Mat resultHost;
                    dst.download(resultHost);
                } else {
                    cv::Mat dst;
                    cv::bilateralFilter(srcHost,dst,3,1,1);
                }
            }

            //cv::imshow("Result",resultHost);
            //cv::waitKey();

        } catch(const cv::Exception& ex) {
            std::cout << "Error: " << ex.what() << std::endl;
        }

    std::clock_t end = std::clock();
    std::cout << double(end-begin) / CLOCKS_PER_SEC  << std::endl;
}

Like this:

$ g++ `pkg-config opencv --cflags --libs` -o test test.cpp
$ ./test

I get Errors:

/tmp/ccq7bU2Y.o: In function `main':
test.cpp:(.text+0x7e): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0x9d): undefined reference to `cv::cuda::GpuMat::defaultAllocator()'
test.cpp:(.text+0xb7): undefined reference to `cv::cuda::GpuMat::defaultAllocator()'
test.cpp:(.text+0xfe): undefined reference to `cv::cuda::GpuMat::upload(cv::_InputArray const&)'
test.cpp:(.text+0x112): undefined reference to `cv::cuda::Stream::Null()'
test.cpp:(.text+0x17a): undefined reference to `cv::cuda::bilateralFilter(cv::_InputArray const&, cv::_OutputArray const&, int, float, float, int, cv::cuda::Stream&)'
test.cpp:(.text+0x1d3): undefined reference to `cv::cuda::GpuMat::download(cv::_OutputArray const&) const'
/tmp/ccq7bU2Y.o: In function `cv::Mat::~Mat()':
test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccq7bU2Y.o: In function `cv::Mat::release()':
test.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
/tmp/ccq7bU2Y.o: In function `cv::cuda::GpuMat::~GpuMat()':
test.cpp:(.text._ZN2cv4cuda6GpuMatD2Ev[_ZN2cv4cuda6GpuMatD5Ev]+0x14): undefined reference to `cv::cuda::GpuMat::release()'
/tmp/ccq7bU2Y.o:(.data.DW.ref._ZTIN2cv9ExceptionE[DW.ref._ZTIN2cv9ExceptionE]+0x0): undefined reference to `typeinfo for cv::Exception'
collect2: error: ld returned 1 exit status
edit retag flag offensive close merge delete

Comments

Hi did you manage to solve this? I followed that same guide and I am facing right now the same exact problem.

makolele12 gravatar imagemakolele12 ( 2020-07-01 03:01:42 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-05-15 10:52:59 -0600

kbarni gravatar image

Did you check the output of pkg-config opencv --cflags --libs?

First, for OpenCV4 it's pkg-config opencv4 --cflags --libs.

Second, if you compile OpenCV4 yourself, you must enable the pkg-config file generation using the -D OPENCV_GENERATE_PKGCONFIG=ON flag.

edit flag offensive delete link more

Comments

It looks like the OPENCV_GENERATE_PKGCONFIG Bool is deprecated (https://github.com/opencv/opencv/issu...).

My CmakeCache.txt contains the following lines: //Generate .pc file for pkg-config build tool (deprecated) OPENCV_GENERATE_PKGCONFIG:BOOL=OFF

Any other idea to solve the problem with the undefined references? Thanks!

makolele12 gravatar imagemakolele12 ( 2020-07-01 03:05:02 -0600 )edit

It is not deprecated, just the default value is false. To generate the pkg-config file, just pass -DOPENCV_GENERATE_PKGCONFIG=YES as argument when running cmake.

kbarni gravatar imagekbarni ( 2020-07-01 05:17:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-05-15 07:40:03 -0600

Seen: 1,336 times

Last updated: May 15 '20