LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-02-2008, 10:35 AM   #1
HarryBoy
Member
 
Registered: Apr 2008
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215

Rep: Reputation: 16
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
 
Old 05-02-2008, 10:43 AM   #2
ddden
LQ Newbie
 
Registered: Apr 2008
Location: Toronto
Distribution: Ubuntu, Red Hat, LFS
Posts: 14

Rep: Reputation: 0
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.
 
Old 05-02-2008, 10:57 AM   #3
HarryBoy
Member
 
Registered: Apr 2008
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215

Original Poster
Rep: Reputation: 16
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
 
Old 05-03-2008, 02:18 PM   #4
ddden
LQ Newbie
 
Registered: Apr 2008
Location: Toronto
Distribution: Ubuntu, Red Hat, LFS
Posts: 14

Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Makefile error:: all nothing need to be done. knockout_artist Linux - Kernel 9 10-23-2009 04:28 AM
Simple Makefile help sharathkv25 Programming 3 02-21-2007 03:19 AM
Makefile problems/Simple kernel module smoothdogg00 Linux - Kernel 1 10-28-2006 04:16 PM
What is wrong with this simple rule in makefile? George2 Programming 6 05-03-2006 01:53 AM
Problem with a simple makefile julz_51 Programming 1 11-12-2005 12:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration