I sometimes hear poeple saying make is best avoided today. I don't agree with this. For large projects, you're probably better off with CMake, but for tiny-to-medium-small projects, make is really nice. Below are some example Makefiles illustrating where I believe make still shines. All examples assume you're using Linux or a Unix variant.

Any of these examples can be put in a file in the same directory as your source files, named something like "Makefile" or "makefile".

  • Compile and link a simple project of three compiled files
  • Compile and link a project of an arbitrary number of .cpp files, assuming you don't even want to list your .o's, and you only care about .cpp's
  • A slightly more complicated example, with a .h and using clang instead of the default C compiler.



  • Hits: 79
    Timestamp: 2025-09-01 01:52:25 PDT

    Back to Dan's tech tidbits

    You can e-mail the author with questions or comments: