Error in linking cublas Cmake error

I am trying to build my project but it keep giving me an error. I tried to include the /usr/local/cuda-10.0/lib64//libcublas.so.10.0 path, but it does not work.
My cmake file is given below:

  1. cmake_minimum_required(VERSION 2.8) project(testssd) find_package(PkgConfig REQUIRED)

    pkg_search_module(GST REQUIRED gstreamer-1.0>=1.4
    gstreamer-sdp-1.0>=1.4
    gstreamer-video-1.0>=1.4
    gstreamer-app-1.0>=1.4)

    find_package(CUDA REQUIRED)
    message("-- CUDA version: ${CUDA_VERSION}")

    set(
    CUDA_NVCC_FLAGS
    ${CUDA_NVCC_FLAGS};
    -O3
    -gencode arch=compute_62,code=sm_62
    )

    if(CUDA_VERSION_MAJOR GREATER 9)
    message("-- CUDA ${CUDA_VERSION_MAJOR} detected, enabling SM_62")

    set(
    	CUDA_NVCC_FLAGS
    	${CUDA_NVCC_FLAGS}; 
    	-gencode arch=compute_62,code=sm_62
    )
    
    # OpenCV used for findHomography() and decomposeHomography()
    # OpenCV version >= 3.0.0 required for decomposeHomography()
    find_package(OpenCV 3.0.0 COMPONENTS core calib3d REQUIRED)
    

    endif()

    find_package(CUDA)
    find_package(Qt4)
    find_package( OpenCV REQUIRED )

    include(${QT_USE_FILE})
    include_directories(/usr/include/gstreamer-1.0 /usr/lib/aarch64-linux-gnu/gstreamer-1.0/include /usr/include/glib-2.0 /usr/include/libxml2 /usr/lib/aarch64-linux-gnu/glib-2.0/include/ /usr/local/cuda-10.0/lib64/)

    add_definitions(${QT_DEFINITIONS})
    cuda_add_executable(testssd testssd.cpp)

    #link_directories(/usr/local/cuda-10.0/lib64/)

    target_link_libraries(testssd jetson-inference)
    target_include_directories(testssd PRIVATE {GST_INCLUDE_DIRS}) target_link_libraries(testssd {GST_LIBRARIES})
    target_link_libraries( testssd ${OpenCV_LIBS} )
    target_link_libraries( testssd nvinfer_plugin )
    target_link_libraries( testssd nvinfer )

The error while building :
nvidia@nvidia:~/Desktop/test/build$ make
[ 50%] Linking CXX executable testssd
/usr/bin/ld: CMakeFiles/testssd.dir/testssd.cpp.o: undefined reference to symbol ‘cublasScopy_v2@@libcublas.so.10.0
/usr/local/cuda-10.0/lib64/libcublas.so.10.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/testssd.dir/build.make:119: recipe for target ‘testssd’ failed
make[2]: *** [testssd] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/testssd.dir/all’ failed
make[1]: *** [CMakeFiles/testssd.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2

All i can understand from " undefined reference to symbol ‘cublasScopy_v2@@libcublas.so.10.0’ " that the program is not able to link libcublas.so.10.0 but cant solve it.

Hi,

In my system checking the file /usr/share/cmake-3.5/Modules/FindCUDA.cmake, I see that it defines CUDA_LIBRARIES and CUDA_CUBLAS_LIBRARIES, since you are already using find_package(CUDA), perhaps adding a target_link_libraries with these might help.

Adding target_link_libraries(testssd /usr/local/cuda-10.0/lib64/) didnt work !! and i could also see CUDA_LIBRARIES and CUDA_CUBLAS_LIBRARIES but same error

According to cmake documentation https://cmake.org/cmake/help/v3.12/command/target_link_libraries.html if you want to use the absolute path to link, you must provide the full path to the library, that would be target_link_libraries(testssd /usr/local/cuda-10.0/lib64/libcublas.so) instead.

As you are already using find_package(CUDA) I meant that you could try to link using:

target_link_libraries(testssd {CUDA_LIBRARIES}) target_link_libraries(testssd {CUDA_CUBLAS_LIBRARIES})

hello jcaballero,
when i used
target_link_libraries(testssd {CUDA_LIBRARIES}) target_link_libraries(testssd {CUDA_CUBLAS_LIBRARIES})

i got the following error

nvidia@nvidia:~/Desktop/test/build$ cmake …
– CUDA version: 10.0
– CUDA 10 detected, enabling SM_62
– Found OpenCV: /usr (found suitable version “3.3.1”, minimum required is “3.0.0”) found components: core calib3d
– Found OpenCV: /usr (found version “3.3.1”) found components: opencv_calib3d opencv_core opencv_dnn opencv_features2d opencv_flann opencv_highgui opencv_imgcodecs opencv_imgproc opencv_ml opencv_objdetect opencv_photo opencv_shape opencv_stitching opencv_superres opencv_video opencv_videoio opencv_videostab
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cublas_device_LIBRARY (ADVANCED)
linked by target “testssd” in directory /home/nvidia/Desktop/test

– Configuring incomplete, errors occurred!
See also “/home/nvidia/Desktop/test/build/CMakeFiles/CMakeOutput.log”.
See also “/home/nvidia/Desktop/test/build/CMakeFiles/CMakeError.log”.

but then using the full path " target_link_libraries(testssd /usr/local/cuda-10.0/lib64/libcublas.so) " solved it

Thank you very much.