1

I have problem with my makefile. Tree of my project looks as follow:

  • makefile/ makefile
  • source/ main.cpp
  • includes/ first.hpp,

and i have following makefile:

program.o: main.o

      g++ -o program main.o

main.o: /home/project/source/main.cpp, /home/project/include/first.hpp

      g++ -c /home/project/source/main.cpp /home/project/include/first.hpp

How i can create makefile without paths? I mean something like this:

program.o: main.o

       g++ -o program main.o

main.o: main.cpp, first.hpp

     g++ -c main.cpp first.hpp
timrau
  • 22,054
  • 4
  • 51
  • 63
user2178946
  • 9
  • 1
  • 2

2 Answers2

1

Make Tutorial: How-To Write A Makefile

And here's a generic makefile I wrote which handles dependency generation. It's for C, but can be converted to C++ trivially.

Robert S. Barnes
  • 38,391
  • 29
  • 126
  • 177
0

Make is pretty smart and has a number of built-in rules already. Get to know these rules and the predefined macros like CXX, CFLAGS, LDFLAGS, etc. Here's about the simplest Makefile that should build your program:

program: main.o
    $(CXX) $(LDFLAGS) -o $@ $<
main.o: main.cpp first.hpp
Bklyn
  • 2,542
  • 2
  • 20
  • 16