[c++]coding on Linux(1)compile through makefile with g++

[c++]OOP — compile on Linux with g++

This paper records the process of compiling c++ files on Linux with g++. Through write the makefile, successfully compiling a group of simple coding files in c++.

Files Included

h files c files makefile
FE_stdafx.h FE_main.c makefile
FEM_BaseClass.h FEM_BaseClass.c
FEM_UDefined.h FEM_UDefined.c
FEM_Topology.h FEM_Topology.c
FEM_base.h
vim makefile
exe=main
obj=FE_main.o FEM_UDefined.o FEM_BaseClass.o FEM_Topology.o \
#       FEM_base.o

$(exe):$(obj)
    @g++ -o $(exe) $(obj)

FE_main.o : FE_main.c
    @g++ -c FE_main.c

FEM_UDefined.o : FEM_UDefined.c
    @g++ -c FEM_UDefined.c

FEM_BaseClass.o : FEM_BaseClass.c
    @g++ -c FEM_BaseClass.c

FEM_Topology.o : FEM_Topology.c
    @g++ -c FEM_Topology.c

#FEM_base.o : FEM_base.h
#   @g++ -c FEM_base.h


tar :   
    @tar -cf FEM3.0.tar  FE_main.c  FEM_base.h  FEM_UDefined.c \
                     FEM_BaseClass.c  FEM_Topology.c  FEM_UDefined.h \
                     FEM_BaseClass.h  FEM_Topology.h  FE_stdafx.h  makefile
clean:
    rm -rf *.o main

NOTE

The including order of h files is vital. Otherwise, errors occur while compiling. A solution of this problem is to add #pragram once to each of the h files.

猜你喜欢

转载自blog.csdn.net/benzp/article/details/80696902