gcc addlib.c -fPIC -shared -o addlib.so
g++ addlib.c -fPIC -shared -o addlib.so
linux vscode c 引入本地头文件
在项目名称下新建.vscode文件夹
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc 生成活动文件",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc 生成活动文件",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"1.c", //需要编译的.c文件
"2.c", //需要编译的.c文件
"3.c", //需要编译的.c文件
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: /usr/bin/gcc"
}
]
}
1.c
#include <stdio.h>
#include "my_head.h"
#include "ex_head.h"
int main(int argc, char *argv[]){
print();
ppp();
return 0;
}
2.c
#include <stdio.h>
#include "my_head.h"
void print(){
printf("Hello world!\n");
}
3.c
#include <stdio.h>
#include "ex_head.h"
void ppp(){
printf("Hello world2222!\n");
}
ex_head.h
#ifndef ex_head_h
#define ex_head_h
void ppp();
#endif
my_head.h
#ifndef myhead_h
#define myhead_h
void print();
#endif