# CUDA build error

**URL:** <https://discourse.cmake.org/t/cuda-build-error/5610>\
**Category:** Code\
**Created:** [May 4, 2022, 2:09pm UTC](https://discourse.cmake.org/t/cuda-build-error/5610 "2022-05-04T14:09:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakub\_Mitura](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jakub_mitura/32/2257_2.png) [@Jakub\_Mitura](https://discourse.cmake.org/u/Jakub_Mitura)\
**Post date:** [May 4, 2022, 2:09pm UTC](https://discourse.cmake.org/t/cuda-build-error/5610/1 "2022-05-04T14:09:30Z")

</div>

Hello In cmake build I have error that was not present in case when I had compiled it as visual studio project

```auto
atomicAdd_block is undefined

```

I had found in stack overflow that one should set CMAKE\_CUDA\_ARCHITECTURES to at least 70 to avoid this problem, but in my case it still do not work

> <https://stackoverflow.com/questions/69817605/cuda-atomicadd-block-is-undefined>

my includes

```auto
#include <cuda.h>
#include <cuda_runtime.h>
#include <cstdint>
#include <cooperative_groups.h>
#include <vector>
#include <cooperative_groups/reduce.h>
#include <cooperative_groups/memcpy_async.h>
#include <cmath>
#include <iostream>
#include <cmath>
#include <cstdint>
#include <assert.h>
#include "device_launch_parameters.h"

```

code causing problem (was working as visual studio project)

```auto
count = atomicAdd_block(&fpFnLocCounter[0], count);

```

cmake

```auto
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
set(CMAKE_CUDA_ARCHITECTURES 70)
project(hello LANGUAGES CXX CUDA)
enable_language(CUDA)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -lineinfo -lcudadevrt")
add_executable(hello hello.cu )
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
target_link_libraries(${PROJECT_NAME} ${CUDA_LIBRARIES})

```

full repository for reference

```auto
https://github.com/jakubMitura14/HousdorffHDF5cMake

```

thanks for help !

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 4, 2022, 5:36pm UTC](https://discourse.cmake.org/t/cuda-build-error/5610/2 "2022-05-04T17:36:01Z")

</div>

Cc: @robert.maynard

---

<div class="post-metadata">

**Author:** ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)\
**Post date:** [May 4, 2022, 7:13pm UTC](https://discourse.cmake.org/t/cuda-build-error/5610/3 "2022-05-04T19:13:48Z")

</div>

> [@Jakub\_Mitura](#):
>
> `CMAKE_CUDA_ARCHITECTURES`

Your CMakeLists.txt is correct, you just need to ensure you are using CMake 3.18 or newer to have support for this variable.

I see no such issue with your repo when using CUDA 11.6 and CMake 3.23

---

<div class="post-metadata">

**Author:** ![Jakub\_Mitura](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jakub_mitura/32/2257_2.png) [@Jakub\_Mitura](https://discourse.cmake.org/u/Jakub_Mitura)\
**Post date:** [May 5, 2022, 5:35am UTC](https://discourse.cmake.org/t/cuda-build-error/5610/4 "2022-05-05T05:35:31Z")

</div>

Thank you !!!
