using cmake, I got a ploblem compile made by gpu coder static library(.a)

I wannna compile including static library(.a) function made by gpu coder in jetson xavier and execute code on ROS.
I already successed making static library using gpu coder.
I think that in CMakeLists, setting library path is well.
but I got a ploblem when complile .cpp file through cmake in Xavier.
I attach error code and CMakeLists file.
help me!!!!!
/home/nvidia/catkin_ws/src/realtime_inpainting/src/wrapper/wrapper.a(wrapper.o): In function `__sti____cudaRegisterAll()':
tmpxft_00002175_00000000-5_wrapper.cudafe1.cpp:(.text.startup+0x20): undefined reference to `__cudaRegisterLinkedBinary_42_tmpxft_00002175_00000000_6_wrapper_cpp1_ii_96e8f507'
/home/nvidia/catkin_ws/src/realtime_inpainting/src/wrapper/wrapper.a(introsort.o): In function `__sti____cudaRegisterAll()':
tmpxft_0000244e_00000000-5_introsort.cudafe1.cpp:(.text.startup+0x20): undefined reference to `__cudaRegisterLinkedBinary_44_tmpxft_0000244e_00000000_6_introsort_cpp1_ii_5da2a824'
/home/nvidia/catkin_ws/src/realtime_inpainting/src/wrapper/wrapper.a(insertionsort.o): In function `__sti____cudaRegisterAll()':
tmpxft_000024cb_00000000-5_insertionsort.cudafe1.cpp:(.text.startup+0x20): undefined reference to `__cudaRegisterLinkedBinary_48_tmpxft_000024cb_00000000_6_insertionsort_cpp1_ii_54501cbc'
/home/nvidia/catkin_ws/src/realtime_inpainting/src/wrapper/wrapper.a(heapsort.o): In function `__sti____cudaRegisterAll()':
tmpxft_00002530_00000000-5_heapsort.cudafe1.cpp:(.text.startup+0x20): undefined reference to `__cudaRegisterLinkedBinary_43_tmpxft_00002530_00000000_6_heapsort_cpp1_ii_6b1ad24e'
/home/nvidia/catkin_ws/src/realtime_inpainting/src/wrapper/wrapper.a(wrapper_emxutil.o): In function `__sti____cudaRegisterAll()':
tmpxft_0000259e_00000000-5_wrapper_emxutil.cudafe1.cpp:(.text.startup+0x20): undefined reference to `__cudaRegisterLinkedBinary_50_tmpxft_0000259e_00000000_6_wrapper_emxutil_cpp1_ii_74fbff25'
/home/nvidia/catkin_ws/src/realtime_inpainting/src/wrapper/wrapper.a(MWLaunchParametersUtilities.o): In function `__sti____cudaRegisterAll()':
tmpxft_000026fb_00000000-5_MWLaunchParametersUtilities.cudafe1.cpp:(.text.startup+0x20): undefined reference to `__cudaRegisterLinkedBinary_62_tmpxft_000026fb_00000000_6_MWLaunchParametersUtilities_cpp1_ii_3d5deff9'
/home/nvidia/catkin_ws/src/realtime_inpainting/src/wrapper/wrapper.a(wrapper_data.o): In function `__sti____cudaRegisterAll()':
tmpxft_000020c9_00000000-5_wrapper_data.cudafe1.cpp:(.text.startup+0x20): undefined reference to `__cudaRegisterLinkedBinary_47_tmpxft_000020c9_00000000_6_wrapper_data_cpp1_ii_7c19101b'
/home/nvidia/catkin_ws/src/realtime_inpainting/src/wrapper/wrapper.a(wrapper_initialize.o): In function `__sti____cudaRegisterAll()':
tmpxft_0000210a_00000000-5_wrapper_initialize.cudafe1.cpp:(.text.startup+0x20): undefined reference to `__cudaRegisterLinkedBinary_53_tmpxft_0000210a_00000000_6_wrapper_initialize_cpp1_ii_9c24d7b2'
[ 84%] Built target stereoimageproc_exe
collect2: error: ld returned 1 exit status
realtime_inpainting/CMakeFiles/inpainting_cuda.dir/build.make:137: recipe for target '/home/nvidia/catkin_ws/devel/lib/realtime_inpainting/inpainting_cuda' failed
make[2]: *** [/home/nvidia/catkin_ws/devel/lib/realtime_inpainting/inpainting_cuda] Error 1
CMakeFiles/Makefile2:7382: recipe for target 'realtime_inpainting/CMakeFiles/inpainting_cuda.dir/all' failed
make[1]: *** [realtime_inpainting/CMakeFiles/inpainting_cuda.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 86%] Built target tf2_ros_static_transform_publisher
[ 87%] Built target kinect2_bridge
[ 87%] Built target image_rotate
[ 93%] Built target depth_image_proc
[ 94%] Built target kinect2_bridge_nodelet
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

 Accepted Answer

Hi DaHoon,
The static library created by GPU Coder contains reallocatable CUDA device code, that can only be linked by nvcc. g++ cannot link CUDA device code. To fix this issue, you can use nvcc instead of g++ to link. Or use GPU Coder to create a dynamic library (.so), where the device code has already been linked by nvcc, that you can use g++ to link.
Chao

7 Comments

gpu coder generate target option : NVIDIA JETSON only available .a or .exe
so, I only can select static library. How do I link .a file by nvcc??
I already search google etc and try link nvcc but, I can't compile again.
I'm sorry but I need your answer for linked by nvcc.
Could you try this:
link the device code in static library to a device code obj dlink.o using nvcc:
nvcc -arch=sm_35 -dlink wrapper.a -o dlink.o
add dlink.o before warpper.a in your final link command:
g++ ... dlink.o wrapper.a ...
You may need to replace -arch=sm_35 to the compute compability you used in generating the wrapper.a.
Hello, I'm also trying to build a static library from alexnet, only with ROS.
half a year trying to find the source of the error: nvcc fatal: Don't know what to do with '/usr/lib/x86_64-linux-gnu/libconsole_bridge.so.0.4'
I set flags like this:
set (CMAKE_C_COMPILER $ {CUDA_NVCC_EXECUTABLE})
set (CMAKE_CXX_COMPILER $ {CUDA_NVCC_EXECUTABLE})
# Eliminate GCC Specific Compiler Flags
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
set (CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG "")
please tell me where is the source of the problem
Hi Vlasov,
NVCC may not understand a library with version number, like libconsole_bridge.so.0.4. There are two possible solutions.
  1. Create a symbolic link to the library, for example, libconsole_bridge.so -> libconsole_bridge.so.0.4, and link to the symbolic link using NVCC.
  2. Pass the library directly to the host linker by prepending "-Xlinker", for example, nvcc -Xlinker libconsole_bridge.so.0.4 ...
Chao
Could you give an example of how to write this in CmakeList.txt?
Hi Vlasov,
I am not experienced with cmake. And I don't see how libconsole_bridge.so.0.4 was added in your cmake.
One thing you can try:
Search libconsole_bridge.so.0.4 in your cmake, and replace it with libconsole_bridge.so. I assume there is already a soft link from libconsole_bridge.so to libconsole_bridge.so.0.4.
Chao
Excuse me, I don't understand how to link to libconsole_bridge.so. I can't find anything useful on the Internet, could you tell me which command can do this?

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with GPU Coder in Help Center and File Exchange

Products

Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!