So i have multiple .c files in the same directory, which each of them have many functions inside them. and there are times i want to use one function from another .c file. I know there is one method, which is as ff:
- declare the function i want to use in the .c file i want to include it
- then when compiling, use both .c files in the compilation(like gcc -o file1.c file2.c output) but my question is, is there a way to avoid having to use all the .c files in the compile time? let me explain everything with the ff simple codes
//in sourcecode/sum.c
int sum(int x, int y){
return x+y;
}
then in the main.c file i have the ff simple code.
//in sourcecode/main.c
int sum(int x,int y); // i know it's simple to do this in certain .h file and include it
//here but for the sake of simplicity i just didn't do it.
int main(){
printf("the sum of two numbers is %d \n",sum(45,68));
return 0;
}
then when compiling, i just do gcc main.c sum.c -o output but what i don't like is i will have to include all other files in the compile time incase there are a lot of function i am using from other .c files? so is there a way to avoid that?? i heard that just including the .c file, in the caller .c file might work, but i am sceptical as it could mess up during linking.