没有合适的资源?快使用搜索试试~ 我知道了~
Linux中使用VS Code编译调试C++项目详解
42 下载量 123 浏览量
2020-12-25
23:05:04
上传
评论 1
收藏 139KB PDF 举报
温馨提示
前言 关于VS Code在Linux下的安装这里就不提了,不管是CentOS还是Ubuntu,如果不懂且搜问题足够的情况下,你会解决的。 一、前置知识——gcc/g++的编译链接过程 在Windows下,如果你用Visual Studio进行开发,C/C++的编译器一般采用微软提供的MSBuild;在Linux下C/C++的编译器大多采用gcc/g++。既然要在Linux下进行C++开发,很有必要了解一下g++编译器的一些基本知识。 假设我现在有一个最简单的C++文件: #include <iostream> using namespace std; int main() { cou
资源详情
资源评论
资源推荐

Linux中使用中使用VS Code编译调试编译调试C++项目详解项目详解
前言前言
关于VS Code在Linux下的安装这里就不提了,不管是CentOS还是Ubuntu,如果不懂且搜问题足够的情况下,你会解决的。
一、前置知识一、前置知识——gcc/g++的编译链接过程的编译链接过程
在Windows下,如果你用Visual Studio进行开发,C/C++的编译器一般采用微软提供的MSBuild;在Linux下C/C++的编译器大多采用gcc/g++。
既然要在Linux下进行C++开发,很有必要了解一下g++编译器的一些基本知识。
假设我现在有一个最简单的C++文件:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!!!!" << endl;
return 0;
}
接下来如何编译呢?简单来说分成两步:先编译,再链接
1. 安装安装g++编译器编译器
启动终端,进入root模式,安装gcc和g++
Ubuntu:
CentOS:
[xxx@xxx ~]$ su
[xxx@xxx ~]# yum install gcc
[xxx@xxx ~]# gcc --version
[xxx@xxx ~]# yum install gcc-g++
[xxx@xxx ~]# g++ --version
2. 编译编译hello.cpp
[xxx@xxx ~]$ g++ -c hello.cpp
输出结果是一个hello.o文件,这是编译过程的生成的中间文件。-c 表示只编译,不链接。
3. 链接链接hello.o生成生成hello.out
[xxx@xxx ~]$ g++ -o hello.out hello.o
输出结果是一个hello.out文件,这是最终的可执行文件。-o 表示输出文件,hello.o是上一步生成的.o文件。
当然,如果第2、3步是可以合并执行,直接执行命令
[xxx@xxx ~]$ g++ -o hello.out hello.cpp
然而第2、3步分开执行是有意义的,后面会讲到。
4. 运行运行hello.out
最后执行以下hello.out验证一下输出结果呗
[xxx@xxx ~]$ ./hello.out
二、构建项目二、构建项目
实际开发过程中当然不可能只有一个cpp这么简单,有时候会有非常多的.h和.cpp文件相互配合,那么上面直接通过g++编译可执行文件就没那
么简单了。我们需要借助Make这个强大的项目构建工具,帮助我们构建和组织项目代码。
假设现在有如下3个文件:hw2.cpp、solution.h和solution.cpp
/* solution.h */
class Solution {
public:
void Say();
};
/* solution.cpp */
#include <iostream>
#include "solution.h"
void Solution::Say(){
std::cout << "HI!" << std::endl;


















weixin_38499706
- 粉丝: 2
- 资源: 906
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0