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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.