c/c++编译动态链接库&linux vscode c 引入本地头文件

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值