我有以下cmake
文件:
cmake_minimum_required(VERSION 3.5)
project(myapp LANGUAGES C CXX)
find_package(CUDA)
find_library(LIB_LOCATION csv json-c)
INCLUDE(FindCUDA)
list(APPEND CMAKE_PREFIX_PATH /usr/lib /usr/local/lib /usr/local/cuda/lib64)
cuda_add_executable(myapp src/myapp.cu src/ingest/tiles.cpp src/ingest/listings.cpp src/tree.cpp)
target_link_libraries(myapp csv json-c m SFCGAL pthread)
当我运行命令时,它返回:
makefile:63: recipe for target 'myapp' failed
/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.c:576: multiple definition of `main'
./src/myapp.o:/home/user/cuda-workspace/myapp/Default/../src/myapp.cu:83: first defined here
./CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.o:/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.c:295: multiple definition of `info_compiler'
./CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.o:/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp:280: first defined here
./CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.o:/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.c:542: multiple definition of `info_platform'
./CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.o:/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp:527: first defined here
./CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.o:/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.c:543: multiple definition of `info_arch'
./CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.o:/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp:528: first defined here
./CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.o:/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdC/CMakeCCompilerId.c:561: multiple definition of `info_language_dialect_default'
./CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.o:/home/user/cuda-workspace/myapp/Default/../CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp:539: first defined here
collect2: error: ld returned 1 exit status
make: *** [myapp] Error 1
唯一的main
文件在myapp.cu
中是如何实现的?我该如何解决?
更新
在此之后仍然迷失了,而不是专注于代码:(
我做了一个更改,将所有文件(.cu,.c,.cpp,.h)列在这样的变量中:
SET(SRC_FILES
src/myapp.cu
src/math_ext.h
src/tree_alloc.cu
... etc)
CUDA_ADD_EXECUTABLE(myapp ${SRC_FILES})
MESSAGE (DEBUG ${SRC_FILES})
该消息返回正确编译的文件(当然),但在编译期间仍然存在相同的问题。 在此链接中(如建议的那样)cmake finds more than one main function可以选择尝试分离构建。所以我甚至添加了:
install (DIRECTORY "build" DESTINATION "." DIRECTORY_PERMISSIONS
OWNER_WRITE OWNER_READ OWNER_EXECUTE
GROUP_WRITE GROUP_READ GROUP_EXECUTE
WORLD_WRITE WORLD_READ WORLD_EXECUTE)
或替代
FILE (MAKE_DIRECTORY build)
并运行命令:
rm -fR CMakeFiles/; cmake --clean-first --build .
但仍然是同样的问题。
更新2
我认为它的原因是,它试图在Nsight IDE中运行它。
必须是其中的一些设置。