PCL+CUDA一起编译时,CMake报错nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified

具体的警告和报错是这样的:

CMake Warning (dev) in ad-census_generated_main.cu.o.cmake:
  Syntax Warning in cmake code at

    /home/xxx/softwares/AD-Census/build/CMakeFiles/ad-census.dir/ad-census_generated_main.cu.o.cmake:79:198

  Argument not separated from preceding token by whitespace.
This warning is for project developers.  Use -Wno-dev to suppress it.

nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
CMake Error at ad-census_generated_main.cu.o.cmake:206 (message):
  Error generating
  /home/xxx/softwares/AD-Census/build/CMakeFiles/ad-census.dir//./ad-census_generated_main.cu.o

搜了一下,找到了可用的解决方案。来自https://github.com/PointCloudLibrary/pcl/issues/776
处理方法就是在控制CUDA和PCL编译的CMakeLists.txt当中加入如下代码:

get_directory_property(dir_defs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
set(vtk_flags)
foreach(it ${dir_defs})
    if(it MATCHES "vtk*")
    list(APPEND vtk_flags ${it})
    endif()
endforeach()

举例来说,我的CMakeLists.txt原先是这样写的:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(AD-Census)

FIND_PACKAGE(PCL 1.2 REQUIRED)
FIND_PACKAGE(CUDA REQUIRED)
FIND_PACKAGE(OpenCV 3.0 REQUIRED)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_61,code=sm_61;-std=c++11;)

INCLUDE_DIRECTORIES(${PCL_INCLUDE_DIRS}
    ./containers)

LINK_DIRECTORIES(${PCL_LIBRARY_DIRS}
    /usr/lib
    /usr/local/lib)


CUDA_ADD_EXECUTABLE(ad-census
    main.cu
    ./containers/device_memory.cpp
    ./containers/initialization.cpp
)

TARGET_LINK_LIBRARIES(ad-census
    ${OpenCV_LIBS}
    ${PCL_LIBRARIES})

那么就在其中加入上面的代码,变成:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(AD-Census)

FIND_PACKAGE(PCL 1.2 REQUIRED)
FIND_PACKAGE(CUDA REQUIRED)
FIND_PACKAGE(OpenCV 3.0 REQUIRED)

### 我放到了这里
get_directory_property(dir_defs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
set(vtk_flags)
foreach(it ${dir_defs})
    if(it MATCHES "vtk*")
    list(APPEND vtk_flags ${it})
    endif()
endforeach()

foreach(d ${vtk_flags})
    remove_definitions(-D${d})
endforeach()
###

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_61,code=sm_61;-std=c++11;)

INCLUDE_DIRECTORIES(${PCL_INCLUDE_DIRS}
    ./containers)

LINK_DIRECTORIES(${PCL_LIBRARY_DIRS}
    /usr/lib
    /usr/local/lib)


CUDA_ADD_EXECUTABLE(ad-census
    main.cu
    ./containers/device_memory.cpp
    ./containers/initialization.cpp
)

TARGET_LINK_LIBRARIES(ad-census
    ${OpenCV_LIBS}
    ${PCL_LIBRARIES})


就可以了。

你可能感兴趣的:(PCL+CUDA一起编译时,CMake报错nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified)