Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cuda_runtime.h error without even including it

Hi,

I'm written a very simple "hello world" opencv3 program from which I'm going to start my project. But I am getting an error in currently setting an error and I'm not sure if its because of something I did, or a bug (from the latest snapshot of the code that I cloned). Below is the setup.

Here is my CMakeLists.txt file:

cmake_minimum_required ( VERSION 2.8 )

set ( CMAKE_CXX_FLAGS "-std=c++11" )
set ( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
set ( PROJ_NAME "cv_pp" )
set ( PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include )

find_package ( OpenCV REQUIRED )
include_directories ( ${OpenCV_INCLUDE_DIR} )

file ( GLOB_RECURSE PROJ_SRCS src/*.cpp )

include_directories ( "${PROJECT_INCLUDE_DIR}" )
add_executable ( ${PROJ_NAME} ${PROJ_SRCS} )
target_link_libraries ( ${PROJ_NAME} ${OpenCV_LIBS} )

Here is the C++ source file:

#include <iostream>
#include <opencv2/opencv.hpp>

void print_version()
{
    std::cout << "OpenCV version : " << CV_VERSION << std::endl;
    std::cout << "Major version : " << CV_MAJOR_VERSION << std::endl;
    std::cout << "Minor version : " << CV_MINOR_VERSION << std::endl;
    std::cout << "Subminor version : " << CV_SUBMINOR_VERSION << std::endl;
}

int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        std::cerr << "Usage: " << argv[0] << " <Image_Path>\n";
        return -1;
    }

    cv::Mat image;
    image = cv::imread( argv[1], 1 );

    if ( !image.data )
    {
        std::cerr << "No image data \n";
        return -1;
    }

    cv::namedWindow("Display Image", cv::WINDOW_AUTOSIZE );
    cv::imshow("Display Image", image);

    cv::waitKey(0);
    print_version();

    return 0;
}

Here is the error about cuda_runtime that I'm getting:

[100%] Building CXX object CMakeFiles/cv_pp.dir/src/cv_pp.cpp.o
In file included from /usr/local/include/opencv2/cudalegacy.hpp:47:0,
                 from /usr/local/include/opencv2/opencv.hpp:78,
                 from /home/sudarshan/research/cv_pp/src/cv_pp.cpp:4:
/usr/local/include/opencv2/cudalegacy/NCV.hpp:52:26: fatal error: cuda_runtime.h: No such file or directory
 #include <cuda_runtime.h>
                          ^
compilation terminated.
make[2]: *** [CMakeFiles/cv_pp.dir/src/cv_pp.cpp.o] Error 1
make[1]: *** [CMakeFiles/cv_pp.dir/all] Error 2
make: *** [all] Error 2

The error seems to indicate that I haven't linked the CUDA libraries to my exe. I'm aware of this since I haven't linked it in my CMakeLists.txt. However, I'm not including cuda_runtime.h in code. This means that opencv2/opencv.hpp must include it in theirs by default. Does this mean I have to link the CUDA libs even if I'm not going to be using any of the CUDA stuff? If that's the case could someone show me how to link the CUDA libs in my CMakeLists file?

Path exports after installing CUDA:

# cuda
export PATH=/usr/local/cuda-7.5/bin:$PATH
export LD_LIBRARY_PATH=/home/user/cudaNN/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH

Platform:

  • Operating System 64-bit Ubuntu 14.04
  • OpenCV 3 built and installed from source following instructions from here, but cloned source from here.
  • Installed Cuda 7.5 along with cudaNN (not required for this error but listing it anyway).

Any help is appreciated.

Thanks, Shaun.