LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-28-2008, 05:07 AM   #1
gajaykrishnan
Member
 
Registered: Jul 2004
Posts: 65

Rep: Reputation: 15
Is there any program that generates the Makefile automatically for C++ programs?


Hi all,

Is there any program that generates the Makefile automatically for C/C++ programs? If there is any good IDE that takes care of all these issues then it is also welcome.

Considering the fact, that the project that I am going to embark upon will involve a lot of code and dependencies, I really don't want to get bogged down and stuck in just writing the correct makefiles.

So, It would be great if I can use some tool that generates these Makefiles automatically for me. I am also searching for some good IDE for developing C++ programs something like we have Eclipse for Java.

Thanks in advance!

Awaiting a reply.
 
Old 05-28-2008, 11:36 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
If you're willing to sacrifice some portability, Makefiles and GCC can actually handle a good load of dependency stuff for you. For example, here's a Makefile I'm using for a small compiler I'm writing for a class right now:
Code:
CXXFLAGS=-g -O2 -Wall -Wextra -Wno-sign-compare -MD -I. -Isrc/
SRCS = $(wildcard src/*.cpp) $(wildcard src/boost/program_options/src/*.cpp)
OBJS = $(SRCS:%.cpp=%.o)
DEPS = $(SRCS:%.cpp=%.d)
BIN = evilc

all: $(BIN)

$(BIN): $(OBJS)
   $(CXX) $(LDFLAGS) -o $@ $^

clean:
   rm -f $(DEPS) $(OBJS) core

.SECONDARY: $(OBJS)

-include $(DEPS)
The key to this working is the -MD flag to gcc and the include directive. The include directive is a GNU make extension, so you lose some portability. I'd recommend reading the GNU make manual, it's chock full of interesting little tricks you can use to write good Makefiles easier.

If you have requirements beyond what make can offer to you easily, I personally like CMake. There are lots of other options available like scons or even (blech!) autotools, YMMV.

As for an IDE, there's a sticky with lots of suggestions. I've heard good things about Eclipse CDT, though I've never used it myself.
 
Old 05-29-2008, 01:59 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
For an example of an universal makefile, see my reply in C programming: Adding new source file to project in the programming section on LQ

Last edited by Wim Sturkenboom; 05-29-2008 at 02:00 AM.
 
Old 05-29-2008, 11:44 AM   #4
seraphim172
Member
 
Registered: May 2008
Posts: 101

Rep: Reputation: 15
Have a look at Anjuta. It's an integrated development environment and allows to handle all compilation and building from the GUI.
http://anjuta.sourceforge.net/

Personally I prefer handmade Makefiles for small to medium sized projects, because it gives a clear overview of the project. 'make' is quite powerful and worth learning, even if it's not very "trendy" these days.

Linux Archive

Last edited by seraphim172; 06-25-2008 at 04:41 AM.
 
  


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
How to generate Prerequisites automatically for makefile Greatrebel Programming 1 03-07-2007 09:32 AM
How to compile the program with the makefile? Nishant Desai Programming 2 07-19-2006 12:07 AM
How to I start programs automatically? tazmad78 Linux - Software 10 03-09-2006 07:22 AM
Require a Makefile for kernel module programs b123coder Linux - Newbie 1 12-28-2004 10:11 AM
program that generates relative paths? TheMaXX Linux - Software 1 10-21-2003 02:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:58 AM.

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