Creating a makefile

For the purpose of this tutorial, you were instructed to create a C++ Project which requires you to create a makefile.

To create a makefile:

  1. In the Project Explorer view, right-click the HelloWorld project folder and select New > File.

  2. In the File name box, type makefile.

  3. Click Finish.

  4. Type the gnu make instructions below in the editor. Lines are indented with tab characters, not with spaces.

    all: hello.exe
    
    # NOTE: ensure the indented lines are indented with tab characters and not space.
    clean:
            rm main.o hello.exe
    
    hello.exe: main.o
            g++ -g -o hello main.o
    
    main.o:
            g++ -c -g main.cpp
  5. Click File > Save.

Your new makefile, along with your main.cpp file are displayed in the Project Explorer view. Your project now contains main.cpp and makefile. You can now build your HelloWorld project.

cdt w newmake02

Related concepts

Related tasks

Related reference


Copyright (c) 2000, 2025 Contributors to the Eclipse Foundation