简体   繁体   English

Makefile结合了fltk和C ++文件

[英]Makefile combining fltk and C++ files

I'm trying to make a C++ program with added FLTK library. 我正在尝试使用添加的FLTK库制作C ++程序。 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: 我认为这可能与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). 因此:Item.o是Bron(武器)和Pancerz(装甲)的基类。 And with Statystyki (statistics) are part of Marine class, which is base for specific ChaosSpaceMarine, SpaceMarine and Tau. 与Statystyki(统计数据)一起属于Marine类,它是特定ChaosSpaceMarine,SpaceMarine和Tau的基础。 GraphicsLib contain several FL/Fl_.... headers, so I can make my own graphic objects. GraphicsLib包含几个FL / Fl _....标头,因此我可以创建自己的图形对象。

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. 感谢Lmis和我的朋友,我更正了我的makefile,如果有人遇到类似问题,我会把它放在上面。

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? 我了解它说存在对main的未定义引用,但是在此文件中没有任何地方有这样的引用,所以怎么了?

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. -o标志告诉编译器您要给它产生的文件使用什么名称。 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. 您在Makefile中说的是,希望编译器使用GraphicsLib.o等对象编译名为main.o程序。

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. 我假设所有.o -files都可以编译,然后此答案可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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