Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm new to c++ and I wanted to know few questions regarding makefile.

1) Is writing makefile really important ? I mean there are many IDE's which does this automatically. Also, do people in programming job write makefiles or do they use automation?

2) Should I learn GNU make or something else like cmake or other ? Can anyone point of pros and cons of these?

share|improve this question

migrated from stackoverflow.com Jun 18 '11 at 1:15

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 3 down vote accepted

Make isn't specific to C++. It's a tool to compare file dates and execute a program against them. It could be a compiler or not. I've used make to automate production tasks.

A number of tools will generate makefiles for you so you can get away with not learning the details.

There are many flavors of make (too many in my opinion). I wouldn't pick out one specifically unless you have a direct need that a specific version fills.

There are times when you will need to know how to write one (setting up a build server, etc). They're generally not that hard to figure out. I wouldn't worry about it until you need to.

share|improve this answer
2  
One "direct need" is portability; that the same makefile be used on all target platforms. Standardizing on GNU make is a good solution for this. (It's also the most powerful. You can do amazing things with it, although the results often make template meta-programming look simple and intuitive.) –  James Kanze Jun 17 '11 at 16:33
    
@James I was thinking that GNU make isn't portable , isn't it? –  user803563 Jun 17 '11 at 16:35
2  
None of the makes are portable with regards to the language they understand; makefiles for GNU make won't run on other makes. But GNU make has the advantage that it is available on all platforms, so you don't have to worry about source compatibility; you just have to get GNU make for the platform, and use it. –  James Kanze Jun 17 '11 at 16:54
    
@James: Writing a fully cross-platform/compiler makefile is nearly impossible. You'd have to define all needed programs (compilers, copy vs cp, etc.) yourself. I wouldn't call any one makefile "portable". –  rubenvb Jun 17 '11 at 17:11

The IDE will generate something sufficient for small projects, where you are working alone, but is quite unwieldable for larger projects: I'm constantly having to edit VS project files by hand, because it's so complicated to do through the GUI, and I'm often frustrated because there's no way to correctly specify the dependencies.

Makefiles have one of the worst syntaxes I've run into, and their dependency management is really, really primitive. (Try adding some comments to a key header, and you'll see what I mean.) Still, I've yet to see anything else that even worked.

My recommendation would be: if you're busy learning C++, or some other language, use the IDE. There's no point in overloading your learning capacity, and anything you'll be doing until you've got some real experience will not be complicated enough to push the IDE to its limits. But expect to have to learn makefiles some time in your career; there are just too many things for which nothing else works.

share|improve this answer
    
+1 for the recommendation.. –  user803563 Jun 17 '11 at 23:30
1  
+1 for the last paragraph. But I feel compelled to point out that I've been using C++ since before Microsoft had a C++ compiler, and Visual Studio since version 1.0, including for some very large projects, and I've never had to edit a project file by hand for C++ (I did for some Visual Studio Extensions in C#.) I wouldn't want anyone to think everyone has to do that regularly; most of us, I would say, don't. –  Kate Gregory Jun 18 '11 at 14:10

It depends on what you are developing. If you are doing this for work and everybody is using the same IDE, then there's no need to use makefiles. If you are working on your own, there is probably no need to learn to use makefiles. However, if it is an open source project, then you probably should learn how to use makefiles. Project files generated by IDEs are usually specific to that IDE. However, the people who contributing to your project may have different preferences of text editors.

share|improve this answer
1  
I use GNU make regularly on Windows (which isn't Unix). On the other hand, I cannot imagine anything being more complicated than it. –  James Kanze Jun 17 '11 at 16:55
    
Are you using it through Cygwin? I was not aware that you could install it on Windows. Or, at least, not easily. Also, as far as automated build tools go, Makefiles are probably the simplest of all of them. –  Zhehao Mao Jun 17 '11 at 17:03
    
Huh, they have scripts for installing it on Windows. I stand corrected then. I will edit the last part of my answer. –  Zhehao Mao Jun 17 '11 at 17:05

I'm something of an authority on Make, it's one of my favorite tools and I use it almost every day. That said, I think it's amazing that no one has come up with anything better in all these years. Make has glaring shortcomings and a long learning curve, but it's the best tool there is for build automation.

I worked as a programmer for years before learning Make (and hated it because my only experience was with other people's badly written makefiles). If you're using something else like an IDE, and it isn't getting in your way, then you can get by fine without Make.

If you do start using Make, go with GNUMake. It's the de facto standard, it's free, it's good, it's GNU, and some other versions have white-space sensitivities and other idiomatic behavior that'll make you tear your hair out.

share|improve this answer
    
+1. I can easily do things in GNU make that are almost impossible in ant. Rake is the first make replacement that may be an improvement. –  kevin cline Jun 18 '11 at 3:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.