linux下编译多个C/C++文件
首先说明gcc是用来编译和运行C文件,g++是用来编译和运行C++文件
以编译和运行C++文件为例:
如果在同一文件下有Head.h, Head.cpp, test.cpp,其中Head.cpp是Head.h的实现,test.cpp包含Head.h文件,那么编译和运行有如下两种方式:
1)同时编译多个文件(顺序随意),并指定输出文件名
g++ -o test Head.cpp test.cpp
./test
2)分别编译源文件,最后链接在一起运行:
g++ -c Head.cpp g++ -c test.cpp g++ -o test Head.o test.o ./test
gcc类似,只需将上述的g++改为gcc即可。