Undefined reference to a function (my function)

I have a fuction declaration:

int Medienwechsel(double xi, double yi, double zi);

then i call this function:

x = 20.0;
y = 20.0;
z = 20.0;
pos = Medienwechsel(x,y,z);

and then it shows the following error:

C:\Users\marti\AppData\Local\Temp\ccMVqLbB.ltrans0.ltrans.o: In function main': <artificial>:(.text.startup+0x3a4): undefined reference to Medienwechsel(double, double, double)’
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\megaatmega2560\firmware.elf] Error 1

The strange thing is, that it word if i use int insted of double…

Hope you can help me!
Thank you!

In which file is the Medienwechsel function implemented (filename + location)?

If you try calling .c code from .cpp code, you must use extern "C" { #include "your header.h" } in the .cpp code.

the function is declared and implemented in the main.cpp. And the main is in the .src

Please show the full source code.

code was here, but the mistake was so stupid…

So you declared the function as taking 3 doubles but implemented the function as taking 3 integers. As far as C++ is concerned, those are different functions (remember. C++ allows overloads of functions with different types).

Since xi, yi and zi are used in for loops as whole numbers, and you can’t have a fraction of a loop iteration, it makes most sense to adapt the declaration to use int too. I.e., correct


int Medienwechsel(int xi, int yi, int zi);

Omg. That day was too long. What a stupid mistake and i was searching hours. :wink:

1 Like