# How to build NVidia NVAPI in slicer environment

**URL:** <https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771>\
**Category:** Development\
**Created:** [August 8, 2024, 9:40am UTC](https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771 "2024-08-08T09:40:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alientex](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@alientex](https://discourse.slicer.org/u/alientex)\
**Post date:** [August 8, 2024, 9:40am UTC](https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771/1 "2024-08-08T09:40:15Z")

</div>

Hello everyone,

I want to add the [nvapi](https://developer.nvidia.com/gameworksdownload#?search=nvapi) SDK to the Slicer environment so that users can choose which GPU to use, similar to how we select a GPU in the NVIDIA Control Panel for a specific application.

Can anybody guide me on how to add the sdk?

Thanks

---

<div class="post-metadata">

**Author:** ![alientex](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@alientex](https://discourse.slicer.org/u/alientex)\
**Post date:** [August 13, 2024, 5:06am UTC](https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771/2 "2024-08-13T05:06:48Z")

</div>

@pieper, @jcfr Is it possible to add such library in slicer?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 13, 2024, 2:12pm UTC](https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771/3 "2024-08-13T14:12:58Z")

</div>

I don’t know of any work in that area, but you could build Slicer from source and link in the library. Or you could write a command line wrapper for the functions you want and then invoke that as a subprocess from Slicer.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [August 13, 2024, 2:58pm UTC](https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771/4 "2024-08-13T14:58:38Z")

</div>

To follow-up on @pieper answer, you may be interested in reviewing the following:

- [https://stackoverflow.com/questions/6165628/use-python-ctypes-to-interface-with-nvapi-follow-up-with-demonstration-code](https://stackoverflow.com/questions/6165628/use-python-ctypes-to-interface-with-nvapi-follow-up-with-demonstration-code)
- [NVAPI-example](https://github.com/verybigbadboy/NVAPI-example/blob/master/example/main.cpp)

It should help you understand how to work with the associated API.

---

<div class="post-metadata">

**Author:** ![alientex](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@alientex](https://discourse.slicer.org/u/alientex)\
**Post date:** [August 23, 2024, 4:07am UTC](https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771/5 "2024-08-23T04:07:27Z")

</div>

> [@pieper](#):
>
> you could write a command line wrapper for the functions you want and then invoke that as a subprocess from Slicer

Hi @pieper, I tried this approach, and it worked perfectly with the wrapper. However, I would like to use the library without the wrapper by linking it directly to the slicer, so I can become familiar with adding other libraries to the slicer in the future.

---

<div class="post-metadata">

**Author:** ![alientex](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@alientex](https://discourse.slicer.org/u/alientex)\
**Post date:** [August 23, 2024, 4:18am UTC](https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771/6 "2024-08-23T04:18:11Z")

</div>

Hi @jcfr,

Thanks for providing the reference links.

I’ve reviewed both links, and my requirement is in C++. I am already familiar with using basic NVAPI functions, and the example link you provided will be additional help.

I am trying to link the library in Slicer, and for that, I’ve created a `CMakeLists.txt` file with the necessary code. I am able to build it without any errors and can include the NVAPI header files in Slicer. However, after writing some basic GPU information retrieval code, I encounter the following error after building Slicer.sln:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/2/92636b1a8a835354e4efa01b88c58ad06f5c8706.png)

@jcfr, I can provide more information about the CMake code and how I built the library if you could help me resolve this issue.

Thank you.

---

<div class="post-metadata">

**Author:** ![alientex](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@alientex](https://discourse.slicer.org/u/alientex)\
**Post date:** [September 5, 2024, 4:27am UTC](https://discourse.slicer.org/t/how-to-build-nvidia-nvapi-in-slicer-environment/37771/7 "2024-09-05T04:27:06Z")

</div>

Hello, can anybody help me solve this issue? I’ve been stuck on this error for several days.

I appreciate any hints or help.

Thank you.
