I have a header file command.h
which contains all my variables and function declarations
//command.h
int someVar1;
int someVar2;
void modifying_loop (int a, int b);
int someVar3;
.
.
.
In another file my_algorithm.c
I define the previously declared function modifying_loop
and use some of the variables declared in the header in
//my_algorithm.c
#include "command.h"
void modifying_loop (int x, int y)
{
someVar1 = x+2;
someVar2 = y+2;
}
And I have my main file command.c
I called the modifying_loop
function like this :
#include "command.h"
int main ()
{
modifying_loop(5,6);
return 0;
}
I compile the it using gcc -o command command.c -lm -lpigpio -L/usr/lib/
which returns me
undefined reference to modifying_loop'
Then to tackle that I link the my_algorithm.c
file by using
gcc -o command command.c my_algorithm.c -lm -lpigpio -L/usr/lib/
which gives me the following :
/usr/bin/ld: /tmp/cc6ad5oo.o:(.bss+0x3c18): multiple definition of `someVar1'; /tmp/ccaydPyq.o:(.bss+0x24918): first defined here
/usr/bin/ld: /tmp/cc6ad5oo.o:(.bss+0x3c1c): multiple definition of `someVar2'; /tmp/ccaydPyq.o:(.bss+0x2491c): first defined here
and same errors for the rest of the variables declared in the header file. Does anyone have any idea what is causing the errors.