We may earn an affiliate commission when you visit our partners.
Subrata Kumar Swain

Understand make tool & write better makefile by understanding what is happening behind the scene(Creation of intermediate files) during building C/C++ programs. We will understand the makefile by using a real time example( "Creation Of Egg Omelet" ).

We are going to do 2 projects during the learning process of makefile.

Read more

Understand make tool & write better makefile by understanding what is happening behind the scene(Creation of intermediate files) during building C/C++ programs. We will understand the makefile by using a real time example( "Creation Of Egg Omelet" ).

We are going to do 2 projects during the learning process of makefile.

PROJECT#1: Without knowing/remembering too many things you will be able to write a makefile for generating binary, shared object(.so), static object(.a), and also get a trick to link from anywhere. After completion of this project Idea of makefile will be cleared. We are creating a makefile template after completing this project and which can be easily used in any project.

PROJECT#2: During implementing this project, we'll improve our makefile and makefile template created in Project#1 by applying patterns, functions.

Every step we will face some problem and then apply the solution.

We will begin with the Then we will come across more technical issues in programming and try to solve them one by one during this journey. Our project structure is in such a way that deployment process will become much easier.

We'll start writing simple makefiles and keep on improving as we really need it. We are doing lots of exercises and facing lots of issues and also fixing all on the fly.

We are going to write a makefile for all possible outputs. In this course you will always learn WHY??? and HOW???

I will show you the real requirement of a particular concept and then we will learn and apply that.

Highlights:

1. Write makefile by knowing minimal things.

2. One Makefile to call all makefiles

3. Makefile with Cross Compilation feature

4. Makefile considering DEBUG & RELEASE version of binary.

5. Passing MACRO from makefile to other makefile

6. Detect environment variables of terminal and one make pass the same to other make.

7. We will discuss high level design(HLD) of the projects and from that you will feel how easy it is to write a makefile.

8. You will be more comfortable with command line compilation

9. Understand shared object linking issues and how to fix it temporarily as well as permanently.

10. Project will be done in MAC and copied to Linux. We will directly do a single make which will call all the modules makefile and build the executables, shared object, static objects seamlessly. IMPORTANT thing is

Enroll now

What's inside

Learning objectives

  • Build c/c++ program using makefile
  • As a c/c++ developer what we should know about makefile!
  • Is makefile difficult? no no no. we'll make it simple. we will focus on how easily we can work in makefile. doing project here, so your concept will be cleared.
  • You will feel this course as a practical guide to makefile.(mac,linux)
  • Cross compilation support
  • Tricks to make it handy!

Syllabus

Introduction & Environment Setup
Introduction
Environment Setup
What's preprocessor, assembler, compiler, linker, expanded source code, .i, .ii, .s, .o, .so, .a, a.out & custom binary.
Read more
What Is Happening Behind The Scene?
Understanding Preprocessor Details
Understand the possible outputs of a C/C++ program and accordingly decide the Folder Structure.
POSSIBLE OUTPUTs OF C/C++ PROGRAM
CREATION OF PROJECT FOLDER STRUCTURE
What is Make & Makefile?Why use make & makefile?How does it work?How make detects changed/updated files?
Make & Makefile
STRUCTURE OF MAKEFILE
REAL WORLD MAKE
WHO WILL CLEAN? (UNDERSTAND PHONY TARGET)
FIRST MAKEFILE(STEP BY STEP DEMO)
OVERRIDE DEFAULT TARGET
Implement 5 modules to produce all the possible outputs.

Download or clone the complete source code from the GitHub link provided. Always read the README. It has all the details.

UNDERSTANDING REQUIREMENT WITH HLD
MOD-1 IMPLEMENTATION & MAKEFILE

The problem in the above makefile

Incremental build issue

Fix the above issue by updating the makefile

Step by step, we will improve the makefile once we feel we really should do it!

Need Of Variables/Macro

Declaring Variables, accessing variables

Make tool internal variables & their purpose($^ $< $@)

How do you generate object files using makefile?


  • ADD LINKER FLAG TO MAKEFILE

  • Revisit source code.

  • Understand the need for a linker flag.

  • Understand how to link the library to an executable

  • Reason for linking math library

  • Reason for not linking libc while using printf() from stdio.h

  • How to know what linker flag to use?

  • Where to add the linker flag?

PLACEMENT OF COMPILER FLAG

Example code demonstrates why we should use a warning flag

Unused variable detection technique

Feel the necessity of compiler flag

Where to keep compiler flag

Explanation of Wall & Werror

Improving our makefile by adding Compiler flags(CFLAGS) and Linker flags(LDFLAGS)

Modify mod1 C code to C++ code

Concatenate variables in the makefile

Accessing the path of libs, and objs in a robust way!

  • Clean targets

MOD-2 RQ, DESIGN, IMPLEMENT & CMDLINE COMPILATION DEMO

Copy module 1 makefile & do the necessary modifications to achieve makefile for .so

Use -fPIC in Makefile

test target introduced to generate test binary

build_dir target introduced to generate directories

What happens if the output binary name has having .cpp extension?

Where Are We(MOD-2)

'install' target is introduced to copy headers to share header location to make its access easier.

MOD-3 HLD

Implementing MOD-3

Modify MOD-1 Makefile to create mod-3 Makefile

Without writing the path of header files in the C/C++ source file, how to position it in a makefile? (INCLUDE FILE search path)

  1. More optimization in Makefile.

  • Cmd to use for static lib generation

  • What is a static library

  • Why rcs

  • Understand changes needed for converting .so Makefile to '.a' makefile

  • Writing test module to verify if generated '.a' is usable.

  • Command line demo(linking to .a file)

MOD 5 HLD
  • MOD-5 Source code & Makefile

  • Add 'install' target to mod-4

Review PROJ#01(5 MODULES RQ)
How to define a macro out side make and use it inside our program
  • Minimum what we should know for writing makefile.

  • Place for compiler & linker flags.

  • Understand CFLAGS & LDFLAGS.

Accessing macro in the program without defining it.

Passing macro from the command line. The same way can be followed inside a makefile.

  • Demonstrate std::async

  • Why need -std

  • When -std is mandatory

  • Where to write it in makefile

  • Compiling using C++2a

  • C++20 Vs C++17 Vs C++2a

  • How to detect the C/C++ standard to use?

  • What is Lazy initialization & Instant initialization

  • Why == & :=

  • When := is used

  • Failing under a situation where == fails and := solves the problem

Demonstrate usages of .PHONY target

How to decide the target can be PHONY

If not defining PHONY, what problem may arise?

Understand the template parameters to use in project.Cross Compiler setup, macro to take timestamp of build binaries and more.

From the understanding of makefile from above PROJECT#01, we are preparing a template which can be used in future projects.

Additionally, we are adding the following:

BUILD_TIME_STAMP which will be helpful to track the release binaries' build time(Helpful if any issue comes from the customer place. Detecting if the shared package is correct or not)

INSTALLATION_PATH: This makes the system handy for deployment.

Cross Compilation feature

A better way of accessing bins, libs and other folders

Copy headers during the building

Understand each attribute used in the template makefile.

Object name collision issue

Understanding attributes used in makefile

Architecture, Design, .so & .a creation

Discuss What we are going to do in this project. (Project explanation with High-Level Design)

Project Source code explanation. Discuss about the plan for makefile & common makefile(Single make to build all modules)


How to use the makefile template to create an employee static library.

How to use the makefile template to create database manager shared object(Dynamic Library).

Create a makefile for the UI Controller module from the template that we have already created.

See how the build is successful but later finds the run fails.

See how run fails. It is a common issue you might have seen in realtime projects. .so not found!

Fix .so not found issue in MAC

Fix .so not found issue in Linux

Know about upcoming plan.

What Will Learn In Upcoming Release!

How to call makefile from makefile. How to pass variable from one makefile to another makefile

1. How to write a common makefile to call other makefiles.

2. Build using single make.

3. Run the binary. (Run from such a location from where our executable should be able to find the dependent libs)

  • One way: Make our binary run from any location and detect the dependent libraries.

  • Tips on how to debug dependency issues in MAC & Linux.

  • Another robust way to run our binary from anywhere which can detect the dependent libraries.

  • Do export inside the makefile.

How To Do CROSS-COMPILER Setup for C & C++.

Use the features of GNU Make(Function & Patterns) for optimising makefile.

WHY WE NEED FUNCTIONS & PATTERNS

  1. Understand the problem of adding new source files in a module.

  2. Rules & Recipes in Makefile

An example of 'db_mgr' is taken. If adding a new file db_writer.cpp, we need to modify the Makefile to build newly added .cpp files. Don't you think, we need an automated way, by which make can auto-detect our modules?

Understanding FUNCTION&PATTERN

  1. Decide/Configure obj file name & binary file names from source file

  2. Using function & pattern - The beginning

  3. Substitution reference


    • ASSIGNMENT IN VIDEO: PRINT ALL C & C++ FILES PRESENT IN CURRENT DIRECTORY

An assignment given in the previous section is covered here.

LIVE DEMO: Detecting all source, Determine obj & binary file names.


LIVE DEMO:

Create 3 cpp files t1.cpp t2.cpp t3.cpp & write a simple makefile to generate the binaries as t1 t2 t3.

  1. Write a simple makefile to build all cpp files present in a specific directory

  2. Demo shown. But no obj generated.

Live demo-How to generate Object files(Without using the pattern in target)

Explain the evaluation of the previously discussed makefile and do the modification with the concepts that we already discussed previously.

Generate object/bin files using patterns in Rules- Failed!

Live demo: Trying to generate object files using patterns, in the Rules in makefile.

Approach Using pattern fails & Why it fails, is explained.

Nice Trick is explained, how to convert to pattern.

OPTIMIZED MAKEFILE:

How to generate Object files(Using patterns in rules)

The trick is explained.

DB_MGR OPTIMIZED Makefile Using Patterns(Don't Skip)
OPTIMIZE MAKEFILE OF UI and EMPLOYEE modules (DON'T SKIP)
  • Discuss the plan to modify the Common Makefile.

  • Why $$ ?

In old Common Makefile, what are we doing?

What things can be optimised? Step by step explanation.


OCM-Optimize Common Makefile


  • How to write a function and call a function

  • Modify our Common Makefile by using the above concept of Function & Patterns

  • Calling the function in the proper place with proper arguments

  • Difference Between OLD & New Makefile

  • The problem in the running make(i.e 2Times Make run is needed)

  • How to write our new makefile that can run only once to do the build perfectly.

CAN SKIP-LIVE DEMO OF 2TIMES MAKE RUN & Understand the root cause.

  • Live Demo: How to handle dependency in makefile.

  • Modify db_mgr makefile and run common make file only once to get the libraries & binaries.

  • $(MAKE) & make

Try to build the final project.
  • Just copy the Project folder from MAC to Linux, and see without any modification in makefile, it works fine.

  • Live Demo by runing uic binary.

Tips For C Programmers.

Write a Makefile to handle Profiling
You'll get essential programming and debugging tips to enhance real-time development skills, making you more efficient and confident in tackling development challenges.
How To Debug Memory Leak In MAC OS

Good to know

Know what's good
, what to watch for
, and possible dealbreakers
Teaches how to write Makefiles for C/C++ projects, which is essential for managing complex builds and dependencies in software development
Explores cross-compilation features within Makefiles, enabling developers to build software for different architectures from a single development environment
Covers debugging shared object linking issues, which can be a common pain point in C/C++ development, especially when dealing with dynamic libraries
Uses GNU Make, a widely-used build automation tool, which is valuable for developers working on Linux and macOS platforms
Focuses on using Makefiles to manage both DEBUG and RELEASE versions of binaries, which is crucial for optimizing software for development and deployment
Requires access to both macOS and Linux environments to fully replicate the project setups, which may be a barrier for some learners

Save this course

Save GNU Make & Makefile To Build C/C++ Projects(LINUX,MAC)[2024] to your list so you can find it easily later:
Save

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in GNU Make & Makefile To Build C/C++ Projects(LINUX,MAC)[2024] with these activities:
Review C/C++ Compilation Process
Solidify your understanding of the steps involved in compiling C/C++ code, including preprocessing, compilation, assembly, and linking, to better grasp how Make automates this process.
Show steps
  • Research the four stages of compilation: preprocessing, compilation, assembly, and linking.
  • Identify the file extensions associated with each stage (e.g., .i, .s, .o).
  • Summarize the role of the linker in combining object files and libraries.
Read 'Managing Projects with GNU Make'
Deepen your understanding of advanced Make features and best practices for managing large projects.
Show steps
  • Obtain a copy of 'Managing Projects with GNU Make'.
  • Read the chapters on pattern rules and macro functions.
  • Experiment with implementing these features in your own makefiles.
Makefile Debugging Exercises
Sharpen your debugging skills by working through a series of exercises that involve identifying and fixing errors in makefiles.
Show steps
  • Find or create makefiles with common errors (e.g., incorrect dependencies, missing variables).
  • Use Make's debugging features (e.g., -n, -d) to trace the execution of the makefile.
  • Identify and correct the errors, verifying the fix by running Make successfully.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Create a Makefile for a Multi-File Project
Apply your knowledge by building a makefile for a real-world C/C++ project with multiple source files, headers, and libraries.
Show steps
  • Choose a C/C++ project with multiple source files and dependencies.
  • Design a makefile that compiles all source files and links them into an executable.
  • Implement dependencies to ensure proper build order.
  • Add targets for cleaning the build directory and running tests.
Document a Complex Makefile
Improve your understanding and communication skills by documenting a complex makefile, explaining its structure, variables, and rules.
Show steps
  • Select a complex makefile from a project you've worked on or found online.
  • Create a document explaining the purpose of each variable and target.
  • Describe the dependencies and build process in detail.
  • Include diagrams or flowcharts to visualize the makefile's structure.
Read 'Autotools: A Practitioner's Guide to GNU Autoconf, Automake, and Libtool'
Expand your knowledge of build automation by exploring Autotools, a suite of tools often used with Make for creating portable build systems.
Show steps
  • Obtain a copy of 'Autotools: A Practitioner's Guide'.
  • Read the introductory chapters on Autoconf and Automake.
  • Understand how Autotools can be used to generate makefiles.
Contribute to a Project Using Make
Gain practical experience by contributing to an open-source project that uses Make for its build system.
Show steps
  • Find an open-source project on GitHub or GitLab that uses Make.
  • Identify an issue or feature you can contribute to.
  • Fork the repository and make your changes, including updating the makefiles if necessary.
  • Submit a pull request with your changes.

Career center

Learners who complete GNU Make & Makefile To Build C/C++ Projects(LINUX,MAC)[2024] will develop knowledge and skills that may be useful to these careers:
Build Engineer
A Build Engineer is responsible for creating and maintaining the systems that compile, link, and package software. This course is directly relevant to the role of a build engineer, as it extensively covers makefiles, a crucial tool for managing the build process of C and C++ projects. The course teaches how to write, understand, and debug complex makefiles, including topics such as cross-compilation, shared object linking, and dependency management, all of which are essential for build engineers. This course helps a build engineer manage a project's build process. Additionally, the course provides hands-on experience creating makefile templates, which is an important element of a build engineer role.
Software Configuration Manager
A Software Configuration Manager is tasked with ensuring software projects are well-organized and controlled, overseeing the build process, versioning, and deployment. This course directly helps in managing builds, a core responsibility for a software configuration manager, particularly for C and C++ projects. It provides insights into creating organized and efficient build systems using makefiles. The ability to understand and debug makefiles, including how they handle dependencies, cross compilation, and different build outputs which are covered in this course helps improve a software configuration manager's ability to troubleshoot and optimize build processes. The course also teaches how to create reusable makefile templates, which is crucial for maintaining consistency across projects. This may be especially useful if they use version control systems to manage code branches or releases.
DevOps Engineer
A DevOps Engineer is responsible for automating and optimizing the software development lifecycle, including build and deployment processes. This course provides vital skills for a DevOps Engineer, especially those working with C or C++ projects. A DevOps engineer needs to have a good understanding of build systems, and this course delivers a comprehensive understanding of makefiles, the standard tool for building C and C++ projects. The course provides instruction on how to create robust and scalable build processes. The concepts taught, such as dependency management, cross-compilation, and creating reusable makefile templates, directly enhance a DevOps engineer's capacity to design and implement efficient pipelines, thus boosting continuous integration and continuous deployment workflows. The practical projects in the course help the learner implement the theory in real-world scenarios.
Embedded Software Engineer
An Embedded Software Engineer develops the software that runs on devices with limited resources. This often includes the need to use makefiles to manage the build process for embedded systems written in C or C++. This course may equip an embedded software engineer with knowledge of makefiles, which are essential for building and debugging the software used in embedded systems. The course covers important aspects, such as cross compilation, handling of shared and static libraries, and custom build configurations, all of which are often encountered in embedded software development. The course provides hands-on experience with makefiles. The course helps an embedded software engineer to build robust and reliable software for embedded devices.
Systems Programmer
A systems programmer works on low-level software, such as operating systems, device drivers, or system utilities. This role involves working at the level of the system and is often coded in C or C++. This course provides skills required for a systems programmer, because makefiles are a key tool for managing the build process when working with system software. The course covers relevant topics such as how to handle compiler and linker flags, how to manage dependencies and create reusable build configurations using makefile templates. This course helps a systems programmer build and maintain complex software systems. Furthermore, by providing practical experience with makefiles, it allows a systems programmer to develop and test software more efficiently.
Software Developer
A Software Developer writes, tests, and maintains software applications. This course is useful for a software developer, especially those who work with C or C++ applications. While not every software developer works with makefiles directly, understanding how build processes work is important, particularly when working on larger projects. This course's exploration of makefiles can help a software developer understand how source code is transformed into executable programs, including how to manage dependencies, library linking, and cross compilation. The course will help them troubleshoot issues that may arise when building software. This course helps a software developer get better at deploying and maintaining code.
Release Engineer
A Release Engineer is responsible for managing the process of releasing software to end-users, ensuring that the systems required for building, packaging, and deploying are well-maintained. This course may be useful for a release engineer, as it provides foundational knowledge of makefiles, a key tool for building C and C++ software. The course covers important aspects of the build process, including dependency management, cross-compilation, and how to create different types of build outputs such as static and shared libraries. The course also provides insights into debugging and optimizing makefiles, which is important for ensuring smooth and efficient release processes. The skills gained in this course help a release engineer build and deploy software with greater control and consistency.
Technical Lead
A Technical Lead guides software development teams, providing technical direction and ensuring that projects are completed on time and within budget. This course may be useful for a technical lead, particularly one who manages projects that use C or C++, because it provides insights into makefiles, a common tool used in these environments to manage the build process. It will help a technical lead better understand build systems, dependency management, and creating configuration files. This course enhances a technical leader's ability to oversee build processes. This course helps a technical lead facilitate collaboration and maintain overall project quality.
Software Architect
A Software Architect is responsible for designing the high-level structure of software systems, ensuring that they meet the functional and non-functional requirements of a project. While a software architect may not be directly involved in writing makefiles, the principles and concepts explored in this course may provide valuable insights into the build process. Understanding how software is compiled, linked, and packaged, gives the architect a better picture of a system they design. It may help an architect to make better decisions about system integration and deployment strategies. Furthermore, the course provides practical experience with makefiles, which will help them appreciate the challenges of building complex applications. This course may help a software architect design systems that are easier to build, maintain, and deploy.
Quality Assurance Engineer
A Quality Assurance Engineer tests software to ensure that it meets the required standards of quality. In the context of C and C++ projects, understanding the build process, which this course explores through examples using makefiles, may be beneficial. This course provides insights into how software is compiled, linked, and packaged, which can help a quality assurance engineer understand the different stages of software development. It may help with troubleshooting when setting up testing environments or diagnosing build-related issues. The knowledge gained may help a quality assurance engineer to create more effective testing strategies. This course may be useful for a quality assurance engineer involved in C and C++ projects.
Project Manager
A Project Manager is responsible for planning, executing, and closing software projects, ensuring they meet deadlines and budget constraints. This course may help a project manager, especially one managing C or C++ projects, by giving them insight into the build process through examples in makefiles. Understanding build systems, which are touched upon in this course, may allow a project manager to better grasp the technical processes. This can help when scheduling and allocating resources. The course may provide an understanding of dependency management, cross compilation, and build output, all of which are important aspects of software projects. This course may help a project manager manage software projects more effectively by better understanding the technical elements.
Technical Consultant
A Technical Consultant advises organizations on how to improve their technology strategies and infrastructure. This role requires a broad understanding of various technical aspects, which may be informed by the knowledge of build systems provided by this course. Although technical consultants may not write makefiles themselves, understanding the complexities involved in the build process can help them better analyze and advise on development workflows. This course may help a technical consultant understand the potential time and resource costs by observing how makefiles handle dependencies, cross compilation, and configuration. It may help them to better assess and recommend efficient strategies for technology companies, including those focused on C and C++ projects.
Data Engineer
A Data Engineer designs, builds, and manages the infrastructure required for data storage, processing, and analysis. While this role might not often use makefiles directly, a basic understanding of how software projects are built and managed can be beneficial. This course may help a data engineer understand how software engineering tools are used to manage large projects. They may also be able to create more effective software workflows. This course may be useful for a data engineer who interacts with software development teams.
Hardware Engineer
A Hardware Engineer designs, develops, and tests physical hardware components and systems. While this role primarily focuses on hardware, a basic understanding of build processes related to software, especially for embedded systems, may be useful. This course may provide insights into the processes used for building and deploying software that interacts with hardware. Although a hardware engineer may not create makefiles every day, understanding how software integrates with hardware components, as well as ways to manage them may inform design decisions. This course may be beneficial to a hardware engineer who works closely with software implementation.
IT Support Specialist
An IT Support Specialist provides technical assistance and support to users, troubleshooting and resolving computer-related problems. While this role is primarily focused on IT infrastructure and services, a basic understanding of how software is built and managed can be helpful sometimes, particularly in environments where custom software is developed. This course may provide a basic understanding of build processes and the tools used in them. This course may be useful for an IT support specialist working in environments that involve software development or system administration.

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in GNU Make & Makefile To Build C/C++ Projects(LINUX,MAC)[2024].
Provides a comprehensive guide to using GNU Make for managing complex software projects. It covers advanced topics such as conditional execution, pattern rules, and macro functions, which can significantly enhance your makefile writing skills. This book is particularly useful for understanding the more advanced features of Make that go beyond the basics covered in the course. It serves as a valuable reference for building robust and maintainable build systems.
Delves into the Autotools suite, which works in conjunction with Make to create portable build systems. While the course focuses on Make itself, understanding Autotools provides a broader perspective on build automation. This book is more valuable as additional reading to expand your knowledge of build systems. It is commonly used by developers who need to support multiple platforms.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser