错误“对`__cudaRegisterLinkedBinary的未定义引用”;用CMake编译CUDA时 [英] Error "undefined reference to `__cudaRegisterLinkedBinary" when compiling CUDA with CMake
问题描述
我正在尝试使用CMake编译使用C ++和CUDA的程序。
CMakeLists的用于编译c ++文件的部分已经制作好了,我将添加该部分来编译CUDA文件。
我添加了源,并且它们可以编译,但是当链接部分出现时,它停止了。
这是CMakeLists.txt文件:
I'm trying to compile a program that uses C++ and CUDA using CMake. The part of CMakeLists that compiles the c++ files were already made and I'm adding the part to compile the CUDA files. I added the sources and they compile ok, but when the linking part comes it stops. Here's the CMakeLists.txt file:
cmake_minimum_required (VERSION 2.6)
set (CMAKE_CXX_STANDARD 11)
set(PROJECT_NAME "UFFS - Empty Project" CACHE STRING "Nome do Projeto")
project (${PROJECT_NAME})
find_package(OpenGL REQUIRED)
find_package(CUDA REQUIRED)
add_subdirectory (external)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/rpavlik-cmake-modules-1c73e35")
include(CreateLaunchers)
include(MSVCMultipleProcessCompile)
if(INCLUDE_DISTRIB)
add_subdirectory(distrib)
endif(INCLUDE_DISTRIB)
set(CUDA_NVCC_FLAGS -Wno-deprecated-gpu-targets;-rdc=true;-std=c++11)
include_directories(
external/glfw-2.7.6/include
external/glm-0.9.4.0
external/glew-1.9.0/include
external/RVO2/include
external/GoTools/gotools-core/include
external/GoTools/parametrization/include
external/SFML/include
external/OpenNL/include
CUDA/include
.
)
add_library(ant_teak_bar STATIC IMPORTED)
set_property(TARGET ant_teak_bar PROPERTY IMPORTED_LOCATION external/AntTweakBar/lib/libAntTweakBar.a)
add_library(openNL STATIC IMPORTED)
set_property(TARGET openNL PROPERTY IMPORTED_LOCATION external/OpenNL/lib/openNL.a)
set(ALL_LIBS
${OPENGL_LIBRARY}
${CUDA_LIBRARY}
GLFW_276
GLEW_190
RVO
parametrization
pthread
sfml-audio
sfml-window
ant_teak_bar
openNL
)
add_definitions(
-DTW_STATIC
-DTW_NO_LIB_PRAGMA
-DTW_NO_DIRECT3D
-DGLEW_STATIC
-D_CRT_SECURE_NO_WARNINGS
)
file(GLOB main_src
"*.h"
"*.hpp"
"*.cpp"
"CUDA/include/CUDA/*.cuh"
"OpenCL/*.cpp"
"common/*.cpp"
"common/*.hpp"
"common/*.h"
)
cuda_compile(
AGENT_O CUDA/_Agent.cu
)
cuda_compile(
GEOMETRIC_O CUDA/cudaGeometric.cu
)
cuda_compile(
KERNEL_O CUDA/kernel.cu
)
cuda_compile(
RVOAGENT_O CUDA/RVOAgent.cu
)
cuda_compile(
RVOSIMULATOR_O CUDA/RVOSimulator.cu
)
cuda_add_executable(main ${main_src}
${DLINK_O}
${AGENT_O}
${GEOMETRIC_O}
${KERNEL_O}
${RVOAGENT_O}
${RVOSIMULATOR_O}
${CUDA_LIBRARY}
)
set_target_properties(main PROPERTIES XCODE_ATTRIBUTE_CONFIGURATION_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/")
create_target_launcher(main WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/")
create_default_target_launcher(main WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/")
target_link_libraries(main ${ALL_LIBS})
SOURCE_GROUP(common REGULAR_EXPRESSION ".*/common/.*" )
if (NOT ${CMAKE_GENERATOR} MATCHES "Xcode" )
add_custom_command(
TARGET main POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/main${CMAKE_EXECUTABLE_SUFFIX}" "${CMAKE_CURRENT_SOURCE_DIR}/"
)
elseif (${CMAKE_GENERATOR} MATCHES "Xcode" )
endif (NOT ${CMAKE_GENERATOR} MATCHES "Xcode" )
这是cmake输出:
-- Could NOT find Boost
failed to create symbolic link '/home/fcg/Desktop/TCC_CUDA_LINUX/TCC_OPENCL/external/GoTools/lrsplines2D/data' because existing path cannot be removed: Is a directory
CMake Warning (dev) at external/rpavlik-cmake-modules-1c73e35/CreateLaunchers.cmake:196 (string):
Policy CMP0053 is not set: Simplify variable reference and escape sequence
evaluation. Run "cmake --help-policy CMP0053" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
For input:
'@USERFILE_ENVIRONMENT@@LAUNCHER_LINESEP@@_arg@'
the old evaluation rules produce:
'LD_LIBRARY_PATH=:$LD_LIBRARY_PATH@LAUNCHER_LINESEP@LD_LIBRARY_PATH=:$LD_LIBRARY_PATH'
but the new evaluation rules produce:
'@USERFILE_ENVIRONMENT@@LAUNCHER_LINESEP@@_arg@'
Using the old result for compatibility since the policy is not set.
Call Stack (most recent call first):
external/rpavlik-cmake-modules-1c73e35/CreateLaunchers.cmake:275 (_launcher_process_args)
CMakeLists.txt:105 (create_target_launcher)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at external/rpavlik-cmake-modules-1c73e35/CreateLaunchers.cmake:251 (get_target_property):
Policy CMP0026 is not set: Disallow use of the LOCATION target property.
Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
The LOCATION property should not be read from target "main". Use the
target name directly with add_custom_command, or use the generator
expression $<TARGET_FILE>, as appropriate.
Call Stack (most recent call first):
external/rpavlik-cmake-modules-1c73e35/CreateLaunchers.cmake:280 (_launcher_create_target_launcher)
CMakeLists.txt:105 (create_target_launcher)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at external/rpavlik-cmake-modules-1c73e35/CreateLaunchers.cmake:196 (string):
Policy CMP0053 is not set: Simplify variable reference and escape sequence
evaluation. Run "cmake --help-policy CMP0053" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
For input:
'@USERFILE_ENVIRONMENT@@LAUNCHER_LINESEP@@_arg@'
the old evaluation rules produce:
'LD_LIBRARY_PATH=:$LD_LIBRARY_PATH@LAUNCHER_LINESEP@LD_LIBRARY_PATH=:$LD_LIBRARY_PATH'
but the new evaluation rules produce:
'@USERFILE_ENVIRONMENT@@LAUNCHER_LINESEP@@_arg@'
Using the old result for compatibility since the policy is not set.
Call Stack (most recent call first):
external/rpavlik-cmake-modules-1c73e35/CreateLaunchers.cmake:265 (_launcher_process_args)
CMakeLists.txt:106 (create_default_target_launcher)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at external/rpavlik-cmake-modules-1c73e35/CreateLaunchers.cmake:251 (get_target_property):
Policy CMP0026 is not set: Disallow use of the LOCATION target property.
Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
The LOCATION property should not be read from target "main". Use the
target name directly with add_custom_command, or use the generator
expression $<TARGET_FILE>, as appropriate.
Call Stack (most recent call first):
external/rpavlik-cmake-modules-1c73e35/CreateLaunchers.cmake:270 (_launcher_create_target_launcher)
CMakeLists.txt:106 (create_default_target_launcher)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fcg/Desktop/TCC_CUDA_LINUX/TCC_OPENCL
这是 make输出中出现错误的部分:
And here's the part of the "make" output that the error appears:
[ 14%] Linking CXX executable main
CMakeFiles/cuda_compile.dir/CUDA/cuda_compile_generated__Agent.cu.o: In function `__sti____cudaRegisterAll_41_tmpxft_0000156c_00000000_7__Agent_cpp1_ii_59b6e43a()':
/tmp/tmpxft_0000156c_00000000-4__Agent.cudafe1.stub.c:11: undefined reference to `__cudaRegisterLinkedBinary_41_tmpxft_0000156c_00000000_7__Agent_cpp1_ii_59b6e43a'
CMakeFiles/cuda_compile.dir/CUDA/cuda_compile_generated_cudaGeometric.cu.o: In function `__sti____cudaRegisterAll_48_tmpxft_000015a3_00000000_7_cudaGeometric_cpp1_ii_f05e008c()':
/tmp/tmpxft_000015a3_00000000-4_cudaGeometric.cudafe1.stub.c:11: undefined reference to `__cudaRegisterLinkedBinary_48_tmpxft_000015a3_00000000_7_cudaGeometric_cpp1_ii_f05e008c'
CMakeFiles/cuda_compile.dir/CUDA/cuda_compile_generated_kernel.cu.o: In function `__sti____cudaRegisterAll_41_tmpxft_000015da_00000000_7_kernel_cpp1_ii_ac061e5b()':
/tmp/tmpxft_000015da_00000000-4_kernel.cudafe1.stub.c:2: undefined reference to `__cudaRegisterLinkedBinary_41_tmpxft_000015da_00000000_7_kernel_cpp1_ii_ac061e5b'
CMakeFiles/cuda_compile.dir/CUDA/cuda_compile_generated_RVOAgent.cu.o: In function `__sti____cudaRegisterAll_43_tmpxft_00001611_00000000_7_RVOAgent_cpp1_ii_5e2ad135()':
/tmp/tmpxft_00001611_00000000-4_RVOAgent.cudafe1.stub.c:11: undefined reference to `__cudaRegisterLinkedBinary_43_tmpxft_00001611_00000000_7_RVOAgent_cpp1_ii_5e2ad135'
CMakeFiles/cuda_compile.dir/CUDA/cuda_compile_generated_RVOSimulator.cu.o: In function `__sti____cudaRegisterAll_47_tmpxft_00001535_00000000_7_RVOSimulator_cpp1_ii_a19d5d58()':
/tmp/tmpxft_00001535_00000000-4_RVOSimulator.cudafe1.stub.c:11: undefined reference to `__cudaRegisterLinkedBinary_47_tmpxft_00001535_00000000_7_RVOSimulator_cpp1_ii_a19d5d58'
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:2235: recipe for target 'main' failed
make[2]: *** [main] Error 1
CMakeFiles/Makefile2:71: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
我查了一下,显然当我使用-rdc = true标志编译CUDA程序时,我需要做一个额外的步骤来正确链接cuda库,但是我不知道该怎么做在cmake中,我确实尝试将 $ {CUDA_LIBRARY}添加到与 target_link_libraries(main $ {ALL_LIBS})链接的 $ {ALL_LIBS}中,但是没有用。
I looked it up and apparently when I compile CUDA programs using the -rdc=true flag I need to do an extra step to link the cuda libraries properly, but I have no idea of how to do that in cmake, I alredy tried adding the "${CUDA_LIBRARY}" to "${ALL_LIBS}" that's linked with "target_link_libraries(main ${ALL_LIBS})" but that didn't work.
推荐答案
如果您查看 https://cmake.org/cmake/help/v3.0/module/FindCUDA.html ,您会发现自己的通话
If you look at https://cmake.org/cmake/help/v3.0/module/FindCUDA.html, you will find that your calling
find_package(CUDA REQUIRED)
定义 CUDA_LIBRARIES
,而不是 CUDA_LIBRARY
。
我想更改此设置将解决您的问题。
defines CUDA_LIBRARIES
, not CUDA_LIBRARY
.
I suppose that changing this will solve your problem.
这篇关于错误“对`__cudaRegisterLinkedBinary的未定义引用”;用CMake编译CUDA时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!