惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
爱范儿
爱范儿
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
Project Zero
Project Zero
小众软件
小众软件
T
Tailwind CSS Blog
量子位
博客园 - 聂微东
I
Intezer
美团技术团队
S
SegmentFault 最新的问题
T
Tor Project blog
Spread Privacy
Spread Privacy
V
Vulnerabilities – Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Jina AI
Jina AI
罗磊的独立博客
B
Blog RSS Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
C
Cisco Blogs
L
LINUX DO - 热门话题
Last Week in AI
Last Week in AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AI
AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
L
LINUX DO - 最新话题
Know Your Adversary
Know Your Adversary
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
The Register - Security
The Register - Security
L
LangChain Blog
博客园 - 叶小钗
T
Tenable Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

C

各位大佬, C 語言該怎麼練習啊 - V2EX 分享一个代码优化导致的死循环 - V2EX 人再笨还能写不出内存安全的 C? - V2EX 想念 C - V2EX C11 的 _Generic,现实当中用得多不多?(尤其是公司项目) 坑爹的 GBK:大家都应该去用 UTF-8 - V2EX 分享一个用 AI 学习 C 语言的例子 一个简单的 C 程序,但是不明白区别在哪里 我这段 C 代码可以在编译时候输出结构体的大小,你们还有什么好点子, show me the code! - V2EX 这段话是否正确?「取余这个运算,只有 Python 是对的。当初 C 这个老师教错了,那么一大票学生也就只敢跟着老师错。只有 Python 敢于站出来坚持正确答案。」 - V2EX C 中可变参数如何直接传递到 printf() - V2EX C 的内存打印实现 - V2EX 函数能否实现透传不定长度参数,最终由 printf 打印 请大佬帮忙修改一份 elf 文件里的数值 - V2EX Linux 上 C 的程序遇到个异常退出问题,局部变量大小有限制?? 将资源嵌入到可执行文件中并保持目录结构 - V2EX 一个简单实用的 C 工程示例, 附简洁的 Makefile - V2EX 关于 C 语言的相关问题 - V2EX 轮子更新: C/C++ 跨平台小工具库 - V2EX 为什么下列程序进行的是无符号乘法? - V2EX 用 riscv64- Linux -gnu-gcc 编译的 c 文件为啥能在 x8664 下运行? - V2EX char *s = "0123"和 char s[] = "0123"的区别 有人能完整地解释一下 int (*daytab) [13]和 int *daytab[13]吗 在 c 语言中, int a;是 declaration 还是 definition - V2EX 一个简单(奇怪)的 C 语言问题 - V2EX c 语言中打印指针的值打印的是 OS 分配的虚拟地址的值吗?要怎么知道 OS 给这个 c 程序进程分配的虚拟地址的大小呢? - V2EX gcc 是怎么找到 system 函数的定义(实现)的? - V2EX 用 C 实现轻量级表达式完成策略定制化和模板内容生成 - V2EX c 语言是如何给汉字编码的? - V2EX 还是不太理解 C 静态库和动态库? - V2EX 开源 C 库 bfdev: MPI 大数运算 - V2EX C 语言中的面向切面编程(AOP) - V2EX 网络语言污染/扭曲专业术语名词——《为什么 c 语言这么抽象?》 - V2EX C 语言函数资源开销可观测性 - V2EX C 语言用户态函数可观测性 - V2EX 在 C 中,如何正确拷贝字符串 - V2EX c 语言中自定义 section 段问题请教 - V2EX C 语言的源码过滤功能的工具 - V2EX 求助 libcurl 的 curl_easy_pause() 使用方法 - V2EX 各位有什么深入了解 C 语言的书嘛? - V2EX 不熟悉 cmake,请教一下多模块项目的 cmake 写法 - V2EX 大家有没有值得推荐的 c 语言的开源项目,用来学习或者贡献的。 - V2EX 求帮忙看一下这个 C 代码为什么会段错误! - V2EX int 型返回值所能表达的内容极限 - V2EX 刚刚突然感受到了 C 语言指针的神奇之处 - V2EX 开源 C 语言库 Melon 之模块选择性编译 - V2EX 这年头搞 c 还有前途吗 看看我的 leetcode 第 151 题目 反转字符串 - V2EX 百变开源 C 语言库日志模块 - V2EX 最好用的 C 语言 JSON 解析器 - V2EX
C 语言新手求助:如何在 vscode 中使用第三方库? - V2EX
craiiz · 2024-07-08 · via C

背景是这样的:最近闲着报了个深圳人社的 c 语言培训班。 完了之后想要把之前自己写的 python 图片处理脚本用 C 写一遍。 然后就发现没法引用第三方库(也许是自己哪里做错了)。

想要达成的目的

  1. 在 vscode 中使用第三方库;
  2. 了解我的 .vscode 里面的配置文件是不是哪里写错了?

当前情况及无法解决的问题(已 google 和 gpt)

以使用第三方库 fmt 为例,按照下述操作之后,在测试文件 test.c 里面输入 #include <f vscode 能自动联想出#include <fmt/format.h> ,但是在 debug 或 run without debug 时终端会报错以下内容 :

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\xxx\Desktop\C\test.c).

cannot open source file "cmath" (dependency of "C:\Users\xxx.vscode\extensions\ms-vscode.cpptools-1.20.5-win32-x64\bin\fmt\format.h"). Please run the 'Select IntelliSense Configuration...' command to locate your system headers.

fmt/format.h: No such file or directory

已经进行的操作

  1. gcc/gdb 都已经正常安装并且可以在终端正常使用; 其中,gcc 路径为:C:\MinGW\bin\gcc.exe ; gdb 版本为 GNU gdb (GDB) 7.6.1 ;

  2. 包管理用的是 vcpkg; 安装到包的路径是:C:\vcpkg\installed\x64-windows\include

  3. vscode 装了插件:C/C++ v1.20.5

  4. 在 google 操作之后下来,之后相关文件内容如下:

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/vcpkg/installed/x64-windows/include",
                "C:/MinGW/include"
            ],
            "defines": [],
            "windowsSdkVersion": "10.0.18362.0",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "gcc",
            "args": [
                "-g",
                "${file}",
                "-I",
                "C:/vcpkg/installed/x64-windows/include",
                "-L",
                "C:/vcpkg/installed/x64-windows/lib",
                "-lfmt",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe"
            ],
            "group": "build"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe build active file",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ]
}

launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
            "MIMode": "gdb",
            "miDebuggerPath": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }

    ]
}

测试脚本

#include <fmt/format.h>

int main(void){

    int a = 1;
    fmt::print("a is {}", a);
    
    return 0;
}