Makefile to separate files in C
Hello,
I would like to compile a makefile that separate files. I read some tutorials, do some tests but I can not do. I want to compile for three files. I can not find any solution for this. If you guys have done this before, then please let me know. Thanks in advance. Also, any example will be appreciated.
Re: Makefile to separate files in C
Hello,
See if this example can help you.
Here is the code
Code:
all: program PROG2 prog3
program: program.c
gcc-o program program.c
PROG2: program2.c
gcc-o program2.c PROG2
prog3: prog3.c
gcc prog3.c prog3, o
Also, if you want to compile everything, simply type make. If you want to compile only prog3, you can type make prog3
Re: Makefile to separate files in C
Hello,
Even i do have a similar kind of a problem. Even i am looking to compile a group of file to create a makefile. By cons I know where I read it, but it was said on a site that was not nice to make the kind MakeFile. And I do not know in advance how much is the size of the file. I would like to compile the example foo *. c. But unfortunately this is not working. If you have a solution for this then it is appreciated. Thanks in advance.
Re: Makefile to separate files in C
Hello,
I understood that you did not want to compile only 3 files. In this case, we must instead do something like this:
Here is the code
Code:
CC=gcc
EXECTE=prog PROG2 prog3
all: ${EXECTE}
%. O:%. C
${CC} $< -O $@
clean:
rm ${EXECTE}
Though I am not sure that this is what you want.
Re: Makefile to separate files in C
Hello,
See if this example interests you
Please take a look at the code
Code:
CC=gcc
CFLAGS=-Wall
main: main.o hello_fn.o
clean:
rm -f main main.o hello_fn.o
I hope that the above code will help you.