# Undefined Reference - different library structure

**URL:** <https://forum.arduino.cc/t/undefined-reference-different-library-structure/344903>\
**Category:** Programming\
**Created:** [November 5, 2015, 10:27pm UTC](https://forum.arduino.cc/t/undefined-reference-different-library-structure/344903 "2015-11-05T22:27:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobs](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@Tobs](https://forum.arduino.cc/u/Tobs)\
**Post date:** [November 5, 2015, 10:27pm UTC](https://forum.arduino.cc/t/undefined-reference-different-library-structure/344903/1 "2015-11-05T22:27:50Z")

</div>

Hello together,

i get some undefined reference due to my different organising structure of my libraries.

```cpp
#include "Project.h"

ModulA modula;
ModulB modulb;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  modula.execute();
  modulb.execute();
}

```

I get this errors:

```cpp
C:\Users\Tobs\Documents\Arduino\ProjectTest/ProjectTest.ino:13: undefined reference to `ModulA::execute()'

C:\Users\Tobs\Documents\Arduino\ProjectTest/ProjectTest.ino:14: undefined reference to `ModulB::execute()'

sketch\ProjectTest.ino.cpp.o: In function `__static_initialization_and_destruction_0':

C:\Users\Tobs\Documents\Arduino\ProjectTest/ProjectTest.ino:3: undefined reference to `ModulA::ModulA()'

C:\Users\Tobs\Documents\Arduino\ProjectTest/ProjectTest.ino:4: undefined reference to `ModulB::ModulB()'

C:\Users\Tobs\Documents\Arduino\ProjectTest/ProjectTest.ino:4: undefined reference to `ModulA::~ModulA()'

C:\Users\Tobs\Documents\Arduino\ProjectTest/ProjectTest.ino:4: undefined reference to `ModulB::~ModulB()'
```

The code ist available on github where you can see the structure of the libraries.  
[https://github.com/huetob/ArduinoIncludeTest](https://github.com/huetob/ArduinoIncludeTest)

```cpp
#ifndef Project_h
#define Project_h

#include "Wire.h"
#include "Arduino.h"

#include "source/ModulA/ModulA.h"
#include "source/ModulB/ModulB.h"

#endif //Project_h

```

If I include the .cpp files, no errors appear. But I think thats the worng way to deal with this problem.

I hope that someone can help me.

Have a nice day,  
Tobs

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 5, 2015, 11:27pm UTC](https://forum.arduino.cc/t/undefined-reference-different-library-structure/344903/2 "2015-11-05T23:27:05Z")

</div>

You should not be using a path in the include statement. When the IDE copies files to the build directory, the structure is flat - everything at the same level, so your include file won't be where you say it is.

You can't hide the use of a library (ModulA and ModulB) from the sketch.

---

<div class="post-metadata">

**Author:** ![Tobs](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@Tobs](https://forum.arduino.cc/u/Tobs)\
**Post date:** [November 6, 2015, 9:54am UTC](https://forum.arduino.cc/t/undefined-reference-different-library-structure/344903/3 "2015-11-06T09:54:37Z")

</div>

Thanks for your fast reply. But how can i have such a structure?  
This is just an example of the current library structure. I have over 30 libraries from this project only and i want to split them in diffrent parts like: Sensors, Motors, Math and Other Stuff.  
I dont want have every single library in the libraries direction because it will be too much.

Regards,  
Tobias

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:33pm UTC](https://forum.arduino.cc/t/undefined-reference-different-library-structure/344903/4 "2021-05-05T21:33:36Z")

</div>

Closed on May 5, 2021, 9:33pm UTC


