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,578
  • 4
  • 51
  • 64
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
  • 39,711
  • 30
  • 131
  • 179
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,559
  • 2
  • 20
  • 16