Thanks to all of you! I had never compiled a program with two cpp filed ... so i was forgetting the second one :) I was compiling with
g++ -Wall main.cpp -o main Big mistake ... now solved. Thanks again
# The following are just convenience variables commonly used in makefiles.# CC is the compiler name and any special flags needed to execute the compiler.# CFLAGS are compile-flags: things like -Wall, -DDEBUG=1, etc.# LFLAGS are link-flags: things like -lm and -lcurses and the like.#
CC = g++
CFLAGS = -Wall
LFLAGS =
# Assuming Unix:
DELFILE = rm -f
# If you are on Windows, use the following instead:#DELFILE = del /q# A 'rule' is a target name, a colon, a list of dependencies, and then the# instructions to compile the target. Each line of instructions must begin# with a TAB character (not spaces!). A dependency is either a file name or# another target in the makefile (or both).## The very first rule names the default target. In other words, if you don't# specify a target name when you run 'make', then the default target is# built. (You can have more than one target in your makefiles. This makefile# has three main targets: 'think', 'clean', and 'cleaner'.)#
think: main.o ThinkingCap.o
$(CC) main.o ThinkingCap.o $(LFLAGS) -o think
main.o: main.cpp ThinkingCap.hpp
$(CC) -c main.cpp
ThinkingCap.o: ThinkingCap.cpp ThinkingCap.hpp
$(CC) -c ThinkingCap.cpp
clean:
$(DELFILE) *.o
# This also removes the executable file.# Works for Unix and Windows... (but may complain about one of the files not# existing to be deleted...)
cleaner: clean
$(DELFILE) think think.exe
Save the file as Makefile in the same directory as your source (main.cpp, etc).
This is only a very basic Makefile. There are other things you can do with it, but don't worry too much about it. The GNU make program has a lot of nice extensions --I tend to use it over the usual make when I am using makefiles.
Makefiles have some significant problems, but are still pretty widely used. But the best part is, they make compiling your program very easy: % make % ./think
Compiles your program and executes it. If you are using GNU make, type % gmake
instead. To get rid of those left-over object files (if you want to recompile everything), make the 'clean' target instead of the default: % make clean