g++ 命令

g++ 编译器的命令

g++ 编译器命令

commanddescription
-cg++ -c file_name is used to only compile and assemble the file_name and not link the object code to produce executable file. It will generate a file_name.o object code file in present working directory.
-o1, compile 2, link 3,generates executable target file
-Epre-compile
-vshow detailed compilation process for example在这里插入图片描述
-g
-I -L -l对于编译多个文件时,这是非常重要的参数。 -I 指定依赖的header所在的目录 -L library-path ,动态加载的库

g++编译文件,不同文件夹

参考这里

总结来说,

  • 写程序的时候,注意include “” , include <> .前者是从相对路径找的,后者是从Path里找的
  • 编译的时候,指定要找的Path, 可以“-I”

缺点:
上面的有个缺点就是,需要在编译的指令上指定所有的参与文件,如果文件少还可以,
文件多的话,这么指定会很麻烦。

vscode可以通过的版本,指定Path, 指定参与文件

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "Taotao Test Building",
			"command": "C:\\MinGW\\bin\\gcc.exe",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"${fileDirname}/list/xixi.h",       // 参与编译的文件1
				"${fileDirname}/list/xixi.c",       // 参与编译的文件2
				"-I",
				"${fileDirname}/list",             // 文件也有加到Path
				"-o",
				"${fileDirname}\\out\\${fileBasenameNoExtension}.exe"
			],
			"options": {
				"cwd": "C:\\MinGW\\bin"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "compiler: C:\\MinGW\\bin\\gcc.exe"
		}
	]
}

g++ 参与编译的文件

1, Approach 1
在上面定义文件时,使用**
例如

"${fileDirname}/list/xixi.h",       // 参与编译的文件1
"${fileDirname}/list/xixi.c",       // 参与编译的文件2

替换为

"${fileDirname}/list/**"

OR

"${fileDirname}/.*
``

### visual code 配置快捷键
|file  | description |
|--|--|
|tasks.json  |ctrl + shift + p  ⇒  tasks  |
|launch.json  |   |
|c_cpp_properties.json  | ctrl + shift + p  ⇒ configurations|

launch.json  第一步是点这个位置,然后会有create xxx
![在这里插入图片描述](https://img-blog.csdnimg.cn/4cceb4a5176c4106939de6d229ea0227.png#pic_center)
![在这里插入图片描述](https://img-blog.csdnimg.cn/fc437b14b377417289e0731073f9f95f.png#pic_center)



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值