g++编译单文件
1、/home/carl下创建一个c++的文件夹
mkdir -p /home/carl/c++
(加上-p防止上一级路径不存在)
2、新建一个main.cpp源代码文件,文件内容使用c++打印出自己的学号
gedit main.cpp
3、使用g++编译并链接main.cpp文件,只编译g++ -o main.o -c main.cpp (-o:指定生成可执行文件的名称 -c:只编译不链接,只生成目标文件。)
链接g++ -o myid main.o
运行./myid
g++编译多文件
1、新建两个文件,分别命名为func.cpp和func.h,分别写入如下内容
#include "func.h"
void print_func1(void)
{
cout<<"using func1—lin"<<endl;
}
#ifndef _FUNC_H
#define _FUNC_H
#include<iostream>
using namespace std;
void print_func1(void);
#endif
2</