I have written c++ program on NetBeans, now I want to run it on Linux on command line. How can I write Makefile, what is the logic of writing it?
I have 3 .cpp files and 2 .hpp files.
This is what I have tried to do:
# Makefile
# the C++ compiler
CXX = g++
CC = $(CXX)
# options to pass to the compiler
CXXFLAGS = -Wall -ansi -O2 -g
Run: Run.cpp Assessment3.o Student.o
$(CXX) $(CXXFLAGS) Run.cpp Assessment3.o Student.o -o Run
Run: Run.cpp Assessment3.hpp Assessment3.o Student.o
$(CXX) $(CXXFLAGS) Run.cpp Assessment3.o Student.o -o Run
Assessment3.o: Assessment3.cpp Assessment3.hpp
$(CXX) $(CXXFLAGS) -c Assessment3.cpp
Student.o: Student.cpp Assessment3.o
$(CXX) $(CXXFLAGS) -c Student.cpp
It gives me ‘missing separator. Stop.’ error on command line. It is not saying that this is an error though.
Cheers
Assuming you want to build an executable named
foo, you can just use a simple makefile which builds everything in one go with just one dependency :EDIT
Alternatively, taking your initial makefile above and fixing a few minor problems: