简体   繁体   中英

Makefile combining fltk and C++ files

I'm trying to make a C++ program with added FLTK library. Separately, files compile. But - I don't know how to combine them into one working file. I think it may be something to do with makefile:

COMP=g++
COMP_FLAGS=$(-Wall -g -std=c++11)
FL_COMP_FLAGS=$(shell fltk-config --cxxflags)
FL_LINK_FLAGS=$( fltk-config --ldflags)


program: main.o GraphicsLib.o ChaosSpaceMarine.o SpaceMarine.o Tau.o
    $(COMP) $(COMP_FLAGS) GraphicsLib.o ChaosSpaceMarine.o SpaceMarine.o Tau.o -o program
main.o: main.cc GraphicsLib.o ChaosSpaceMarine.o SpaceMarine.o Tau.o
    $(COMP) $(COMP_FLAGS) $(FL_LING_FLAGS)  main.cc GraphicsLib.o ChaosSpaceMarine.o SpaceMarine.o Tau.o -o main.o
GraphicsLib.o: GraphicsLib.cc GraphicsLib.h
    $(COMP) $(COMP_FLAGS) $(FL_COMP_FLAGS) -c GraphicsLib.cc
ChaosSpaceMarine.o: ChaosSpaceMarine.cc ChaosSpaceMarine.h Marine.o
    $(COMP) $(COMP_FLAGS)  ChaosSpaceMarine.cc Marine.o -o ChaosSpaceMarine.o
SpaceMarine.o: SpaceMarine.cc SpaceMarine.h Marine.o
    $(COMP) $(COMP_FLAGS) SpaceMarine.cc Marine.o -o SpaceMarine.o
Tau.o: Tau.cc Tau.h Marine.cc
    $(COMP) $(COMP_FLAGS) Tau.cc Marine.o -o Tau.o
Marine.o: Statystyki.o Bron.o Pancerz.o
    $(COMP) $(COMP_FLAGS) Marine.cc Bron.o Pancerz.o Statystyki.o -o Marine.o
Statystyki.o: Statystyki.cc Statystyki.h
    $(COMP) $(COMP_FLAGS) -c Statystyki.cc -o Statystyki.o
Pancerz.o: Pancerz.cc Pancerz.h Item.o
    $(COMP) $(COMP_FLAGS) -c Pancerz.cc -o Pancerz.o
Bron.o: Bron.cc Bron.h Item.o
    $(COMP) $(COMP_FLAGS) -c Bron.cc -o Bron.o
Item.o: Item.cc Item.h
    $(COMP) $(COMP_FLAGS) -c Item.cc -o Item.o

clean: 
    rm -rf Item.o Bron.o Pancerz.o Statystyki.o Marine.o Tau.o SpaceMarine.o ChaosSpaceMarine.o GraphicsLib.o

So: Item.o is base class for Bron(weapon) and Pancerz(armor). And with Statystyki (statistics) are part of Marine class, which is base for specific ChaosSpaceMarine, SpaceMarine and Tau. GraphicsLib contain several FL/Fl_.... headers, so I can make my own graphic objects.

any question and suggestions are welcome here!

EDIT:

Thanks to Lmis and my friend I corrected my makefile, which I put above if anyone have similar problem.

So now I have only one strange error:

g++  -I/usr/local/include -I/usr/local/include/FL/images -c GraphicsLib.cc
g++  -c Statystyki.cc -o Statystyki.o
g++  -c Item.cc -o Item.o
g++  -c Bron.cc -o Bron.o
g++  -c Pancerz.cc -o Pancerz.o
g++  Marine.cc Bron.o Pancerz.o Statystyki.o -o Marine.o
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [Marine.o] Error 1

I understand that it says that there is undefined reference to main, but nowhere in this file is such reference, so what's wrong?

One problem is that:

$(COMP) $(COMP_FLAGS) -o main.o GraphicsLib.o ChaosSpaceMarine.o SpaceMarine.o Tau.o

should be

$(COMP) $(COMP_FLAGS) -o NameOfYourProgram main.o GraphicsLib.o ChaosSpaceMarine.o SpaceMarine.o Tau.o

The -o flag tells the compiler what name you want to give the file it produces. What you said in your Makefile was that you want the compiler to compile program called main.o using the objects GraphicsLib.o and so on.

Since you say

Separately, files compile.

I assume that all the .o -files are compiled just fine and then this answer should fix your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM