johan
johan

Reputation: 45

Makefile for c++ with one .o file and one .CPP file

I am trying to create a makefile to build a windows c++ project on linux. I have to compile .cpp in different directories, to create a library .so with the objects. For that I have created a script to find the .cpp and put it in a file :

SOURCE= \
./Source/CHAINE.CPP\
./Source/CRACKCHN.CPP\
./Source/LISTEPTR.CPP\

Now my makefile looks like : (I know I will have to change the $(TARGET) : $(OBJECT) rule, but thats not my problem here i think)

-include sources.mk
OBJECT = $(SOURCE:%.CPP=%.o)
# 
$(TARGET) : $(OBJECT) 
         $(CC) $(CFLAGS) -o $@ $^ $(LIBS) 

$(OBJECT) : $(SOURCE)
         $(CC) $(CFLAG) $(PREPROC) -c $< -o $(OBJ_DIR)/$@ $(INCLUDE)

But when i do the make command, all the objects are created with the first .CPP (CHAINE.CPP here) :

g++ -Wall -D _MSC_VER -D _GPP -c Source/CHAINE.CPP -o ./Source/CHAINE.o 
===
g++ -Wall -D _MSC_VER -D _GPP -c Source/CHAINE.CPP -o ./Source/CRACKCHN.o
===
g++ -Wall -D _MSC_VER -D _GPP -c Source/CHAINE.CPP -o ./Source/LISTEPTR.o 

This is the first time I have to create a makefile, and I have a lot of problems to solve it, if anybody have a solution?

Upvotes: 1

Views: 1097

Answers (1)

Tomo
Tomo

Reputation: 3531

$(OBJECT) is a list of all objects. With the last rule you seem to want to tell Make how to build a single .o from a single .cpp. It should have a for of:

%.o: %.cpp
    $(CC) $(CFLAG) $(PREPROC) -c $< -o $(OBJ_DIR)/$@ $(INCLUDE)

Upvotes: 2

Related Questions