# Error when attempting to #include \<sl/c\_api/zed\_interface.h\> in a separate file other than main.c

**URL:** <https://community.stereolabs.com/t/error-when-attempting-to-include-sl-c-api-zed-interface-h-in-a-separate-file-other-than-main-c/2328>\
**Category:** C++\
**Created:** [March 27, 2023, 3:41am UTC](https://community.stereolabs.com/t/error-when-attempting-to-include-sl-c-api-zed-interface-h-in-a-separate-file-other-than-main-c/2328 "2023-03-27T03:41:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![josefdmiller](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@josefdmiller](https://community.stereolabs.com/u/josefdmiller)\
**Post date:** [March 27, 2023, 3:41am UTC](https://community.stereolabs.com/t/error-when-attempting-to-include-sl-c-api-zed-interface-h-in-a-separate-file-other-than-main-c/2328/1 "2023-03-27T03:41:31Z")

</div>

Greetings, I would like to break my code up into separate files however, when I attempt to compile with #include \<sl/c\_api/zed\_interface.h\> I get the following error. Is this an issue with the header guards or something? I’m using jetson nano and the most current sdk (3.8.2). Also this is the C API

CMakeFiles/Control\_System.dir/mesh.c.o:(.rodata+0x0): multiple definition of `SL\_VIDEO\_SETTINGS\_VALUE\_AUTO’  
CMakeFiles/Control\_System.dir/main.c.o:(.rodata+0x0): first defined here  
collect2: error: ld returned 1 exit status

My CMakeLists.txt looks like this. All I have done is included my additional files in ADD\_EXECUTABLE and included the math library in target\_link\_libraries.

CMAKE\_MINIMUM\_REQUIRED(VERSION 3.5)  
PROJECT(Control\_System)

if(COMMAND cmake\_policy)  
cmake\_policy(SET CMP0003 OLD)  
cmake\_policy(SET CMP0015 OLD)  
endif(COMMAND cmake\_policy)

SET(EXECUTABLE\_OUTPUT\_PATH “.”)  
find\_package(CUDA ${ZED\_CUDA\_VERSION} REQUIRED)  
include\_directories(${CUDA\_INCLUDE\_DIRS})  
link\_directories(${CUDA\_LIBRARY\_DIRS})

if (WIN32)  
include\_directories($ENV{ZED\_SDK\_ROOT\_DIR}/include/)  
link\_directories($ENV{ZED\_SDK\_ROOT\_DIR}/lib/)

else (WIN32)  
include\_directories(“/usr/local/zed/include/”)  
link\_directories(“/usr/local/zed/lib/”)  
endif(WIN32)

ADD\_EXECUTABLE(${PROJECT\_NAME} main.c mesh.c mesh.h)

target\_link\_libraries(${PROJECT\_NAME} sl\_zed\_c ${CUDA\_CUDA\_LIBRARY} ${CUDA\_CUDART\_LIBRARY} m)

Thank you.

---

<div class="post-metadata">

**Author:** ![BenjaminV](https://community.stereolabs.com/user_avatar/community.stereolabs.com/benjaminv/32/3863_2.png) [@BenjaminV](https://community.stereolabs.com/u/BenjaminV)\
**Post date:** [March 27, 2023, 7:54am UTC](https://community.stereolabs.com/t/error-when-attempting-to-include-sl-c-api-zed-interface-h-in-a-separate-file-other-than-main-c/2328/2 "2023-03-27T07:54:06Z")

</div>

Hi Josef,

When you compiled the c wrapper, did you run `make install` ? This will copy the headers and libraries into the ZED folder (see : [https://www.stereolabs.com/docs/app-development/c/install/](https://www.stereolabs.com/docs/app-development/c/install/)).

You can also take a look at our c tutorials to see what needs to be added in the CMakeLists ; [https://github.com/stereolabs/zed-examples/blob/master/tutorials/tutorial%201%20-%20hello%20ZED/c/CMakeLists.txt](https://github.com/stereolabs/zed-examples/blob/master/tutorials/tutorial%201%20-%20hello%20ZED/c/CMakeLists.txt).

Best,  
Benjamin Vallon

Stereolabs Support

---

<div class="post-metadata">

**Author:** ![josefdmiller](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@josefdmiller](https://community.stereolabs.com/u/josefdmiller)\
**Post date:** [March 27, 2023, 5:09pm UTC](https://community.stereolabs.com/t/error-when-attempting-to-include-sl-c-api-zed-interface-h-in-a-separate-file-other-than-main-c/2328/3 "2023-03-27T17:09:57Z")

</div>

Thank you for the reply, yes I did run make install, this is the location in my jetson.

josef@jetson:/usr/local/zed/include/sl$ ls  
Camera.hpp c\_api  
josef@jetson:/usr/local/zed/include/sl$ cd c\_api/  
josef@jetson:/usr/local/zed/include/sl/c\_api$ ls  
types\_c.h zed\_interface.h  
josef@jetson:/usr/local/zed/include/sl/c\_api$ pwd  
/usr/local/zed/include/sl/c\_api  
josef@jetson:/usr/local/zed/include/sl/c\_api$

Also this is my project layout.

josef@jetson:~/Control\_System$ ls  
build CMakeLists.txt init.c init.h main.c mesh.c mesh.h state.c state.h

As long as I only have the zed\_interface.h in main everything works fine. Its when I attempt to include it in another one of those files. For example I would like to wrap the init code into functions in the init.c file and call them from main. However it if I include it like this.

#include \<sl/c\_api/zed\_interface.h\>  
#include “init.h”

in my init.c file I get the error,

multiple definition of `SL\_VIDEO\_SETTINGS\_VALUE\_AUTO’

I’m pretty sure that the correct #ifndef INIT\_H\_ #define INIT\_H\_ scheme would take care of stuff like that. I just don’t want to add it myself and break something 🙂

---

<div class="post-metadata">

**Author:** ![josefdmiller](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@josefdmiller](https://community.stereolabs.com/u/josefdmiller)\
**Post date:** [March 28, 2023, 6:53am UTC](https://community.stereolabs.com/t/error-when-attempting-to-include-sl-c-api-zed-interface-h-in-a-separate-file-other-than-main-c/2328/4 "2023-03-28T06:53:21Z")

</div>

I think I solved it.

After reading this post:  
[c - Multiple definition of const variables at header file - Stack Overflow](https://stackoverflow.com/questions/24216008/multiple-definition-of-const-variables-at-header-file)

I added the static modifier to this const located in types\_c.h

static const int SL\_VIDEO\_SETTINGS\_VALUE\_AUTO = -1;

This solved the linker error, everything works fine now. I just have to figure out why this worked next. 🙂
