![]() |
using multiple source code files
Hi
I want to use multiple source code file with make but i don't know how if you have any sample or a book please give me thanks my friends |
What you ask is essentially, "tell me how to use make", so you must forgive me if this answer is also very general... I would recommend that you read the GNU Make manual. It contains many examples.
|
thanks
for example i have 3.c 2.c and 1.c
the a() function locate in 3.c the b() function locate in 2.c and in 3.c: int main() { a(); b(); return 0; } please tell me how i link them with other thanks |
You should invoke gcc first on each .c file with the -c option. This means "compile to object file" - i.e. omit the linking stage. Once you have an object file for each .c file, you can link them together:
Code:
gcc -c 1.c -o 1.oCode:
%.o : %.cA simple Makefile which will generate the gcc commands above might look like this. Note that that the 8 spaces before commands should be a TAB in your Makefile - NOT spaces. Code:
myprogram : 1.o 2.o 3.o |
thanks
when i compile 1.c the gcc has errored that tha a() and b() not define
or please define your function while a() is in the 3.c and b() is in the 2.c what i can to do when compiling 1.c |
man gcc
search for a compile option in that manpage |
You need to have a function declaration in a header file which should be included in the file where they are used. You should use the pre-processor to prevent an include file from being read more than once.
So you would make a header file for 1.c, like this: Code:
/* this is 1.h */Code:
/* this is 1.c */Code:
#include "1.h" |
ok
thanks my friend
|
| All times are GMT -5. The time now is 11:41 PM. |