need help with makefile

Sep 24, 2014 at 11:37pm
I am try to make a makefile. but didnt work

i type touch makefile ---> makefile create ----> in the makefile i write this
1
2
3
4
5
6
7
8
9
10
11
12
13
  CC = gcc
  CFLAGS  = -g -Wall

  # the build target executable:
  TARGET = proj1.c

  all: $(TARGET)

  $(TARGET): $(TARGET).c
  	$(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c

  clean:
  	$(RM) $(TARGET)
--->run it

but problem is i chose input file and outfile but dont see an output file


I do have test.txt and proj1.c in same dic
Last edited on Sep 24, 2014 at 11:47pm
Sep 24, 2014 at 11:46pm
for example if i run

I will type

make -f*. make project1

project1 test.txt output.txt

which mean test.txt will be read into code and it will output the on output.txt
Sep 25, 2014 at 12:27am
Fatal error in reader: Makefile, line 7: Unexpected end of line seen
Oct 9, 2014 at 8:47am
use: TARGET = proj1

the target is proj1, but not pro1.c.
Oct 9, 2014 at 11:13am
There are a number of problems.

The target is an executable, not a .c file:
 
TARGET = proj1.c

That should be:
 
TARGET = proj1


The program is dependent on object files. The object files are dependent on source files, but GNU make already knows that, so you don't need to tell it how to compile.

Now, make provides a way of making up object file names, from source file names using text substitution.

So, we need to name the source files:
 
SRCS = proj1.c

And you do have to tell it how to link.
1
2
$(TARGET): $(SRCS:.c=.o)
  	$(LINK.c) $^ -o $@

$^ is the list of sources, proj1.o in this case.
$@ is the name of the target, proj1 in this case.
Use $(LINK.cc) to link C++ programs.


The clean step must also delete the object files:
1
2
clean:
  	rm $(TARGET) $(SRCS:.c=.o)
Last edited on Oct 9, 2014 at 11:21am
Topic archived. No new replies allowed.