g++ 编译器的命令
g++ 编译器命令
command | description |
---|---|
-c | g++ -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. |
-o | 1, compile 2, link 3,generates executable target file |
-E | pre-compile |
-v | show 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)