Reputation: 151
Hello unfortunately I have another problem with my project. The project is a client server program and is used on two machines, one sending image data over TCP to the other. Both machines are Ubuntu 16.04 machines and have OpenCV installed, but only one possesses a CUDA graphics card and has therefore CUDA (8.0) installed, and OpenCV is configured as "WITH_CUDA ON" on the CUDA-computer.
I need to distribute the Server file as executable, because it contains source code I am not allowed to distribute. My goal now is to build an executable which can be distributed to computers (which have opencv and boost installed) independent of CUDA being installed or not.
My minimal CmakeLists.txt
looks as follows:
cmake_minimum_required( VERSION 3.10.0 FATAL_ERROR )
project( Testproject )
# Set c++ standard 11 flag -----------------------------------------------------------------------------------
if( UNIX )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11" )
endif()
# Find and include opencv ------------------------------------------------------------------------------------
set ( OpenCV_DIR /opt/opencv/opencv-3.0/share/OpenCV )
set( OpenCV_FIND_QUIETLY FALSE )
find_package( OpenCV 3.0 REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
# Find Boost package -----------------------------------------------------------------------------------------
find_package( Boost COMPONENTS log log_setup thread system program_options REQUIRED )
include_directories( ${Boost_INCLUDE_DIRS} )
# Find Thread package ----------------------------------------------------------------------------------------
find_package( Threads )
add_executable( Server src/Server.cpp )
target_include_directories(Server PUBLIC /usr/include/spinnaker
PRIVATE ./src/
PRIVATE ../build/ )
target_link_libraries( Server ${OpenCV_LIBS} ${Boost_LIBRARIES} Spinnaker )
On the host machine with CUDA installed, the program builds and runs perfectly. On the non-CUDA machine I get the error:
./Server: error while loading shared libraries: libcudart.so.8.0: cannot openshared object file: No such file or directory.
The strange thing is, CUDA itself is not being used by my code, it seems to be OpenCV that includes the CUDA library but doesn't distribute it. Can anybody help me with the CMakeLists.txt to make Cmake to distribute the libcudart.so.8.0 or better to link it statically within the executable?
How can I check which libs are really linked statically? ldd Server
delivers a list with all dependencies, OpenCV does not occur, but boost. This means that boost is linked dynamically and OpenCV statically, right? Then how could boost being linked statically, too?
Thank you very much for your help again.
Edit 1: In the meanwhile I tried to follow your comments, and it was possible to copy the libcudart.so.8.0
to the non-CUDA computer, and run the program this way. But I would really like to know how to create a Cmake project which statically links the CUDA library, such that it not has to be copied manually. Unfortunately the linked CUDA documentation doesn't help me, I couldn't manage it.
Upvotes: 1
Views: 1088
Reputation: 151
Okay, finally I figured it out and solved the problem. In the end, your comments lead me to the solution. I simply forgot to specify the CUDA library explicitly, which I didn't know I have to do. I changed
target_link_libraries( Server ${OpenCV_LIBS} ${Boost_LIBRARIES} Spinnaker )
to
target_link_libraries( Server ${OpenCV_LIBS} ${Boost_LIBRARIES} Spinnaker ${CUDA_LIBRARIES} )
It is now, as noted in the comments, by default linked statically.
Upvotes: 1