Home

Getting the Most Out of Makefiles

|
Updated:  
2016-03-26 08:29:42
|
C++ For Dummies
Explore Book
Buy On Amazon

Since the beginning of time, or at least since the beginning of the Unix operating system, programmers have used a utility called make to build their applications. And it’s still often used today. The make utility looks at which of your source code files have changed and decides what needs to be compiled and built. Here are some features you can use when working with Makefiles:

  • If your lines run long and you want to continue them on the next line without confusing poor old make, you can end a line with a backslash () and then continue it on the next line.

  • Your best bet when working with Makefiles is to start with one that you know works and then change it so that it applies to your current project. The truth is, almost no programmer creates a Makefile from scratch. Programmers don’t like to work that hard on auxiliary projects like messing with Makefiles. They’d rather get to their programming.

  • Most Makefiles will have a rule called all. The idea behind this rule is that it encompasses all the other rules. When you type make all, you can build your whole project.

  • You can include comments in your Makefiles by starting them with a # character. These comments are not used by the Makefile.

  • Makefiles can include what are called implicit rules, which are rules that pertain to a whole set of files with the same file extension (such as .cpp). These comments can help you understand the Makefiles when working with them.

  • If you don’t like Makefiles, you don’t have to use them. Development environments such as Code::Blocks and Microsoft Visual C++ make it possible to create great applications without ever touching a Makefile.

About This Article

This article is from the book: 

About the book author:

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.

Jeff Cogswell has been an application developer and trainer for 18 years, working with clients from startups to Fortune 500 companies. He has developed courses on C++ and other technologies.