IBit
IBit

Reputation: 400

This makefile only creates .o files

I'm trying to practice using Makefiles for a very simple program. The program files are:

main.cpp
other.cpp
other.h

I want the final executable to be Prog.

What happens when I run this is I get a main.o and other.o but no Prog.

What am I missing here?

## file Makefile

CXXOBJECTS= %.o
CXX= g++ 
CXXSOURCES= main.cpp other.cpp
CXXFLAGS= -std=c++11 -O2


Prog : main.o other.o


main.o : main.cpp 
other.o : other.cpp other.h




## eof Makefile

Upvotes: 1

Views: 416

Answers (1)

user2030052
user2030052

Reputation:

You're almost there. You have the following:

Prog: main.o other.o ## these are your dependencies
    g++ main.o other.o -o Prog

This should give you an executable called Prog. Though actually, a better makefile would be this:

CXXOBJECTS= %.o
CXX= g++ 
CXXSOURCES= main.cpp other.cpp
CXXFLAGS= -std=c++11 -O2

Prog: main.o other.o ## these are your dependencies
    CXX main.o other.o -o Prog

main.o : main.cpp
    CXX CXXFLAGS -c main.cpp

other.o : other.cpp
    CXX CXXFLAGS -c other.cpp

Actually, you can make it even better, but I don't remember the syntactic sugar of makefiles off the top of my head (IDE's :P)

Upvotes: 1

Related Questions