To do this, I tried to make it as simple as possible:
teststb.h :
and teststb.c:
when i compile this with
i get the following error message:
Can someone tell me what I'm doing wrong?
And why are all functions written with the extern keyword ?
Any help would be appreciated.
teststb.h :
C:
#ifndef TESTSTB_H
#define TESTSTB_H
extern void test(void); //test() implementation
#endif //TESTSTB_H
#ifdef TESTSTB_H_IMPLEMENTATION
extern void test(void) //test definition
{
printf("test function executed");
}
#endif //TESTSTB_H_IMPLEMENTATION
and teststb.c:
C:
#include <stdio.h>
#include "teststb.h"
#define TESTSTB_H_IMPLEMENTATION
int main(int argc, char **argv)
{
test();
return 0;
}
gcc -o out2 teststb.c
i get the following error message:
/usr/bin/ld: /tmp/ccFC3JIF.o: in function `main':
teststb.c:(.text+0x14): undefined reference to `test'
collect2: error: ld returned 1 exit status
Can someone tell me what I'm doing wrong?
And why are all functions written with the extern keyword ?
Any help would be appreciated.