默认情况下,除非允许单独编译/链接设备代码,否则CUDA要求在单个翻译/编译单元中编译所有设备代码。
但是我如何在一个cmakelist.txt中为ros(或者更一般的camke)启用它呢?
以下是我当前的cmakelist文件:
cmake_minimum_required(VERSION 2.8.3)
project(edt)
set(ROS_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Debug)
# Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
FIND_PACKAGE(CUDA REQUIRED)
SET(CUDA_NVCC_FLAGS "-arch=sm_61;-g;-G" CACHE STRING "nvcc flags" FORCE)
SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${ZED_INCLUDE_DIRS}
)
cuda_add_executable(
${PROJECT_NAME}_node
src/main.cpp
src/test.cu
src/test2.cu
)
add_dependencies(
${PROJECT_NAME}_node
${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)
## Specify libraries to link a library or executable target against
target_link_libraries(
${PROJECT_NAME}_node
${catkin_LIBRARIES}
${ZED_LIBRARIES}
)
这个
test2.cu定义了在test.cu中调用的函数
(见
cuda_add_可执行文件
在cmakelist中),它当前给出的错误是不能创建.o文件。