
### Create an empty project

```sh
$ xmake create -P test -l cuda
$ cd test
$ xmake
```

<FileExplorer rootFilesDir="examples/other-languages/cuda/basic" />

::: tip NOTE
Starting with v2.2.7, the default build will enable device-link. (see [Separate Compilation and Linking of CUDA C++ Device Code](https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/))
If you want to disable device-link, you can set it with `set_policy("build.cuda.devlink", false)`.
:::

::: tip NOTE
Device functions in cuda source files should be device-linked once and only once. On targets with kind `binary` or `shared` xmake will automatically perform the device-link which takes the static libraries they depend into account, while for `static` targets by default will not be device-linked. However, if the final `binary` or `shared` target do not contain any cuda files, the device-link stage could be missing, resulting in an undefined reference error. In this case the static target should be set `add_values("cuda.build.devlink", true)` manually.
:::

Xmake will detect Cuda SDK automatically and we can also set the SDK directory (or SDK version for default installations) manually.

```sh
$ xmake f --cuda=/usr/local/cuda-9.1/
$ xmake f --cuda=9.1
$ xmake
```

### Specify CUDA SDK Version

Starting from v3.0.5, you can specify the CUDA SDK version via the `--cuda_sdkver` command-line option, giving you precise control over CUDA compilation:

```bash
$ xmake f --cuda_sdkver=11.8
$ xmake
```

Supported version values include:
- `11.8` - Specify CUDA 11.8 version
- `11.x` - Specify CUDA 11.x series version
- `auto` - Auto detect (default)

If you want to known more information, you can see [#158](https://github.com/xmake-io/xmake/issues/158) and [#6964](https://github.com/xmake-io/xmake/pull/6964).
