I am having problem with importing external function to a main c file.
Here is my minimal code:
/* main.c */
#include<stdio.h>
extern int func()
int main(){
extern int func();
}
/*external file with one function that I want to
import*/
#include<stdio.h>
int func(){
printf("Hello World Again\n");
}
I compile and run like this – gcc main.c and then ./a.out but nothing is happening.
Any idea ?
You have to compile the file containing
funcalso(Note that the
-Wallin the compiler command isn’t absolutely necessary but is very good practice)As noted by others, you also need to fix your code to call
funcrather than just re-declaring it.