针对c++中的工程问题在vim中用gcc编写的问题
例如有两个.cpp文件,需要编译,链接这两个文件。那么如何做呢?
//file1.cpp
#include <iostream>
using namespace std;
int add(int x,int y);
int main()
{
int x,y,sum;
cout<<"Enter two numbers:"<<endl;
cin>>x;
cin>>y;
sum=add(x,y);
cout<<"The sum is:"<<endl;
cout<<sum<<endl;
return 0;
}
//file2.cpp
int add(int a,int b)
{
int c;
c=a+b;
return c;
}
在终端中输入以下代码
<pre name="code" class="plain">g++ -c file1.cpp
g++ -c file2.cpp<pre name="code" class="plain">g++ -o file file1.o file2.o
这里的file是链接生成的可执行文件。
输入:
./file即可运行文件了。
本文介绍如何在Vim编辑器中使用GCC编译器进行C++多文件项目的编译及链接过程,包括两个示例源文件的编写、预编译目标文件以及最终生成可执行文件的方法。
898

被折叠的 条评论
为什么被折叠?



