dimanche 23 mars 2014

Linking multiple .c files


Vote count:

0




I have a C file named first.c in which I define an array and call a function which is defined in a C file named second.c. This is how first.c looks:



int main(void)
{
int array[100];
myFunc(*array);
}


second.c on the other hand looks like this:



void myFunc(int array)
{
...
}


But anytime I try to compile these, second.c gives me errors as if it had no idea about the array I passed to its function as an argument. I guess the function doesn't know that at the linking stage. I compile these like this:



gcc -O2 -std=c99 -Wall -pedantic -lm second.c -c
gcc -O2 -std=c99 -Wall -pedantic first.c -c
gcc second.o first.o -o finished


But that's just what I came up with and of course it doesn't work. I guess a Makefile would be in place, but I'm not sure how to implement it.



asked 1 min ago

imre

103





Aucun commentaire:

Enregistrer un commentaire