Simple makefile question
I'm new to makefile questions so be gentle:
I have a hello world cpp app. In the command line if I type: g++ -o program main.cpp then I get an exe called 'program' which executes fine. But I want to use a makefile because I need to learn it for another larger project. My make file is as follows: -------------------------------------- program: main.o g++ -o program main.o main.o: main.cpp g++ -o main.cpp -------------------------------------- Now when I type 'make program' the output I get is: g++ -o main.cpp g++: no input files make: *** [main.o] Error 1 What is wrong with this simple makefile of mine? I am using Fedora. Thanks Harry |
Makefile format
Hi Harry,
The format inside your Makefile is incorrect. Do a search in google to find the format. Here's an example. # The general syntax of a Makefile Target Rule is target [target...] : [dependent ....] [ command ...] So for you: program: program.o gcc -o program program.o something.o program.o: program.c gcc -c program.c ... etc. Hope that helps. Dennis. |
Thanks
Hi,
Thaanks for your quick reply. I noticed that on the last line of my make file the g++ -o main.cpp should have been g++ -c main.cpp I changed it and it now works. I will try your method also. Is my method the wrong way to do it moving forward? Harry |
Makefiles
Hi HarryBoy,
Whatever works for you is what I recommend. :) If you would like examples then quite complex examples exist in anyone of the GNU packages. But I would recommend keeping it simple. |
All times are GMT -5. The time now is 02:29 AM. |