Reputation: 597
I'm running into undefined reference to function during compilation. This is my program:
main.c:
#include <stdio.h>
#include "SSD/ssd.h"
int main(void)
{
printf("%d\n",f());
return 0;
}
SSD/ssd.h:
#ifndef SSD_H
#define SSD_H
int f();
#endif // SSD_H
SSD/ssd.c:
#include "ssd.h"
int f(){
return 4;
}
files ssd.h and ssd.c Are in folder SSD and file main.c and folder SSD are in the same folder. During compilation however I get:
[miku@MikuToshiba Lab5]$ gcc main.c -o run
/tmp/cc9X2i1H.o: In function `main':
main.c:(.text+0xa): undefined reference to `f'
collect2: error: ld returned 1 exit status
I'm running Fedora23
Upvotes: 0
Views: 550
Reputation: 15229
You only build with main.c
, even though SSD/ssd.c
contains code as well.
Include it in your building process:
gcc SSD/ssd.c main.c -o run
Upvotes: 3