【问题标题】:VSCode including header file in cVSCode包括c中的头文件
【发布时间】:2020-03-11 00:18:39
【问题描述】:

我正在尝试在 c 中使用我的头文件。当我使用代码块时,它会处理标题包含部分,但在 vs 代码中,我还无法弄清楚。这就是我在 vs 代码中得到的。这些文件位于同一文件夹中。我正在使用 gcc。

#include "assPQ.h"

。 . .

PS C:\Users\xxx\Desktop\xxxx\ass> cd "c:\Users\xxx\Desktop\xxxx\ass\" ; if ($?) { gcc coffeeShopSimulator.c -o coffeeShopSimulator } ; if ($?) { .\coffeeShopSimulator }
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\xxx\AppData\Local\Temp\cc6RasGF.o:coffeeShopSimulator.c:(.text+0xf): undefined reference to `CreateListPQ'

【问题讨论】:

  • “使用我的头文件”还是使用库?
  • 看起来你的头文件是方形的,这是链接器抱怨它找不到CreateListPQ函数的二进制代码:stackoverflow.com/questions/22426574/gcc-undefined-reference-to
  • 我正在写标题。 assPQ.h 和 assPQ.c 在 main.c 中使用,然后我收到错误消息。
  • 你的构建线是什么?您需要包含 assPQ.c 文件,例如“gcc assPQ.c main.c”
  • { "type": "shell", "label": "gcc.exe build active file", "command": "C:\\MinGW\\bin\\gcc.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:\\MinGW\\bin" }, "problemMatcher": [ "$gcc" ], "group": "build" }你是说这个吗?

标签: c gcc visual-studio-code header include


【解决方案1】:

我解决了这个问题,可能是因为 VS 代码不是一个 IDE,你只能通过这样做来链接

#include "header.c"

主要是。

标题本身发生的事情是 您需要将“header.h”链接到“header.c”和“header.c”链接到“main.c”。

希望这对其他人有所帮助。如果有其他技术解释,我很高兴听到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-16
    • 2012-02-11
    • 2012-02-12
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多