Timing performance using Cuda runtime API undefined reference to `cudaEventCreate'

Hi all,
I am trying to compute the time of execution of an image processing algorithm to get the speed in frame per second, however I got the error after building the file, code , CmakeLists, cmake … and make returns are shown below
Could you please help me resolve this problem, I think it has a problem with Cuda/C++ library linking

the code

#include "opencv2/core/cuda.hpp"
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp"
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/cudafilters.hpp>

    #include <iostream>
    #include <sstream>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
//    #include <GL/glew.h>
//    #include <GL/freeglut.h>

// CUDA utilities and system includes
#include <cuda_runtime.h>
//#include <cuda_gl_interop.h>

//#include <helper_cuda_gl.h>    // CUDA device + OpenGL initialization functions

// Shared Library Test Functions
#include <helper_functions.h>  // CUDA SDK Helper functions
#include <helper_cuda.h>      // includes for cuda initialization and error checking

//using namespace cv;
using namespace std;

int main()
{

cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);

cudaEventRecord(start);

--> my code

cudaEventRecord(stop);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&milliseconds, start, stop);
}

Cmakelists

cmake_minimum_required (VERSION 3.1)
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

project(backgr0)
    find_package(OpenCV REQUIRED)
    find_package(CUDA REQUIRED)
    find_package(GLUT REQUIRED)
    find_package(GLEW REQUIRED)

include_directories(${/usr/local/cuda/})
include_directories (${/usr/local/cuda/lib64/})

    include_directories(${OpenCV_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS} "/usr/local/cuda/samples/common/inc")  #/usr/local/cuda/samples/common/inc   /usr/local/cuda-10.0/include   /usr/local/cuda-10.0/samples/common/inc   "/usr/local/cuda" "/usr/local/cuda/lib64"

    add_executable(cv_backgr0 backgr0.cpp)
    target_link_libraries(cv_backgr0 ${OpenCV_LIBS} ${GLUT_LIBRARY} ${GLEW_LIBRARY})

cmake … return

-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda (found suitable exact version "10.0") 
-- Found OpenCV: /usr/local (found version "4.1.1") 
-- Found CUDA: /usr/local/cuda (found version "10.0") 
-- Found GLUT: /usr/lib/aarch64-linux-gnu/libglut.so  
-- Found GLEW: /usr/include  
-- Configuring done
-- Generating done
-- Build files have been written to: ......../build

make errors:

[ 50%] Building CXX object CMakeFiles/cv_backgr0.dir/backgr0.cpp.o
[100%] Linking CXX executable cv_backgr0
CMakeFiles/cv_backgr0.dir/backgr0.cpp.o: In function `_cudaGetErrorEnum(cudaError)':
backgr0.cpp:(.text+0xe8): undefined reference to `cudaGetErrorName'
CMakeFiles/cv_backgr0.dir/backgr0.cpp.o: In function `main':
backgr0.cpp:(.text+0x11c): undefined reference to `cudaEventCreate'
backgr0.cpp:(.text+0x124): undefined reference to `cudaEventCreate'
backgr0.cpp:(.text+0x244): undefined reference to `cudaEventRecord'
backgr0.cpp:(.text+0x724): undefined reference to `cudaEventRecord'
backgr0.cpp:(.text+0x72c): undefined reference to `cudaEventSynchronize'
backgr0.cpp:(.text+0x73c): undefined reference to `cudaEventElapsedTime'
collect2: error: ld returned 1 exit status
CMakeFiles/cv_backgr0.dir/build.make:158: recipe for target 'cv_backgr0' failed
make[2]: *** [cv_backgr0] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/cv_backgr0.dir/all' failed
make[1]: *** [CMakeFiles/cv_backgr0.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Thnaks in advance for any help

It appears that I have two folders of Cuda one under the names of ‘Cuda’, the second is under the name of ‘Cuda-10.0’
I noted that when I comment all Cuda runtime functions the header file still indicate an error

In function `_cudaGetErrorEnum(cudaError)':
(.text+0xe8): undefined reference to `cudaGetErrorName'
collect2: error: ld returned 1 exit status

Any help please

Hi,

The source need to be compiled with nvcc.

Please update the CMakeLists.txt with this change:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5112ec6..2be4ff2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,5 +15,5 @@ include_directories (${/usr/local/cuda/lib64/})
 
     include_directories(${OpenCV_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS} "/usr/local/cuda/samples/common/inc")  #/usr/local/cuda/samples/common/inc   /usr/local/cuda-10.0/include   /usr/local/cuda-10.0/samples/common/inc   "/usr/local/cuda" "/usr/local/cuda/lib64"
 
-    add_executable(cv_backgr0 backgr0.cpp)
+    cuda_add_executable(cv_backgr0 backgr0.cpp)
     target_link_libraries(cv_backgr0 ${OpenCV_LIBS} ${GLUT_LIBRARY} ${GLEW_LIBRARY})

Thanks.

Hi AastaLLL,
Thank you a lot for your help
compiling the source code with nvcc solved the problem many thanks