$(CC)は、Cプログラムのコンパイルに使用されます。$(CXX)は、C++プログラムのコンパイルに使用されます。同様に、$(CFLAGS)はCプログラムに使用され、$(CXXFLAGS)はC++のコンパイルに使用されます。
最初の数行を次のように変更します。
#CC = g++
LOADLIBES = -lm
CXXFLAGS = -Wall -O2 -g
(ただし、-O2と-gの間の非互換性に関する他の人のメモを参照してください。)
この行の括弧内のスペースを削除します。
OBJS = $(SRC1:.cpp=.o)
main
行を次のように変更します。
main: $(OBJS) $(SRC2)
# Built by implicit rules
結果のmakefileは次のようになります。
#CC = g++
LOADLIBES = -lm
CXXFLAGS = -Wall -O2 -g
SRC1 = Agent.cpp Breeder.cpp CandidateSolution.cpp \
Cupid.cpp FateAgent.cpp Grid.cpp Reaper.cpp \
fitness.cpp
SRC2 = main.cpp
SRC = $(SRC1) $(SRC2)
OBJS = $(SRC1:.cpp=.o)
AUX = $(SRC1:.c=.h)
main: $(OBJS) $(SRC2)
# Built by implicit rules
.PHONY: clean
clean:
rm -f *.o main
出力は次のようになります。
$ make
g++ -Wall -O2 -g -c -o Agent.o Agent.cpp
g++ -Wall -O2 -g -c -o Breeder.o Breeder.cpp
g++ -Wall -O2 -g -c -o CandidateSolution.o CandidateSolution.cpp
g++ -Wall -O2 -g -c -o Cupid.o Cupid.cpp
g++ -Wall -O2 -g -c -o FateAgent.o FateAgent.cpp
g++ -Wall -O2 -g -c -o Grid.o Grid.cpp
g++ -Wall -O2 -g -c -o Reaper.o Reaper.cpp
g++ -Wall -O2 -g -c -o fitness.o fitness.cpp
g++ -Wall -O2 -g main.cpp Agent.o Breeder.o CandidateSolution.o Cupid.o FateAgent.o Grid.o Reaper.o fitness.o -lm -o main
完全を期すために、これは私がUbuntu10.04で使用しているmakeのバージョンです。
$ make -v
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i486-pc-linux-gnu