Answer the question
In order to leave comments, you need to log in
How to correctly build a C++ CUDA project using Cmake on Linux?
It is not possible to write Cmake correctly so that it is possible to build the project. An undefined reference to `main' error is thrown.
Project structure:
main.cpp
include
-- CUDA_wrappers.hpp
src
-- CUDA.cu
cmake_minimum_required(VERSION 3.8)
project(Mandelbrot_set)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp include/CUDA_wrappers.hpp src/CUDA.cu)
# LIBGD Package
find_package(GD REQUIRED)
include_directories(${GD_INCLUDE_DIR})
# CUDA Package
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
# Compile CU files
list( APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_20,code=sm_20; -std=c++11")
cuda_compile(CudaKernel src/CUDA.cu)
cuda_add_library(CudaKernels src/CUDA.cu)
# COMPILE AND LINK
cuda_add_executable(Mandelbrot_set $(SOURCE_FILES) CudaKernels)
target_link_libraries(Mandelbrot_set ${GD_LIBRARIES} ${CUDA_LIBRARIES})
Answer the question
In order to leave comments, you need to log in
cuda_compile(CudaKernel src/CUDA.cu)
cuda_add_library(CudaKernels src/CUDA.cu)
cuda_add_library(CudaKernels ${CudaKernel})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question