【问题标题】:gcc - fatal error: libusb.h: No such file or directorygcc - 致命错误:libusb.h:没有这样的文件或目录
【发布时间】:2020-06-21 20:20:14
【问题描述】:

我正在使用 64 位 Windows 7 上的 Visual Studio Code。 在网上搜索了半天,还是解决不了我的问题:我有一个C程序,里面有libusb.h。每当我尝试使用 gcc 进行编译时,都会出现以下错误:

In file included from min.c:1:0: 
min.h:8:20: fatal error: libusb.h: No such file or directory
#include <libusb.h>
                   ^
compilation terminated.

我在网上尝试了一些解决方案,更改了 c_cpp_properties.json 和 settings.json(导致 VSCode 在#include &lt;libusb.h&gt; 行上没有显示任何错误)。

这是我的文件: c_cpp_properties.json:

{
"configurations": [
    {
        "name": "Win32",
        "includePath": [
            "${workspaceFolder}/**",
            "C:/Users/VAKNIN/Downloads/Orel-thesis/libusb-1.0.23/include/libusb-1.0"
        ],
        "browse": {
            "path":[
                "C:/Users/VAKNIN/Downloads/Orel-thesis/libusb-1.0.23/include/libusb-1.0"
            ]
        },
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "compilerPath": "C:\\MinGW\\bin\\gcc.exe",
        "cStandard": "gnu11",
        "cppStandard": "gnu++14",
        "intelliSenseMode": "clang-x86"
    }
],
"version": 4
}

settings.json:

{
"C_Cpp.intelliSenseEngine": "Tag Parser",
"C_Cpp.commentContinuationPatterns": [
    "/**",
    "C:/Users/VAKNIN/Downloads/Orel-thesis/libusb-1.0.23/include/libusb-1.0"
]
}

在这个问题上几个小时后我很迷茫,我会很感激任何帮助。

编辑: 这是以下命令的完整输出:gcc min.c -o min 其中 min.c 是我唯一的 C 文件。

【问题讨论】:

  • 我会问以防万一。您的程序是否包含单个 .c 文件?
  • 确定在那条路径上有libusb.h吗?对我来说,它位于libusb-1.0.23\include\libusb-1.0
  • @HolyBlackCat 是的,它是一个 c 文件。
  • 那么要么那里没有 libusb.h,要么编译器不知道搜索该路径。请将完整的构建输出附加到您的问题中,包括传递给 GCC 的确切内容。
  • 同样,当您在 Windows 上时,您可能需要使用转义的反斜杠指定构建路径:"C:\\Users\\VAKNIN\\Downloads\\Orel-thesis\\libusb-1.0.23\\include\\libusb-1.0"

标签: c visual-studio-code windows-7-x64


【解决方案1】:

找到您的 libusb 的位置,或者如果您没有它,请从 http://libusb.info/ 获取并构建它,或者获取与您的系统(win32 或 win64)匹配的预构建包。

然后确保编译器的搜索路径包含libusb.h所在的include文件夹的路径,并且链接器的搜索路径包含库所在的路径。

【讨论】:

  • 我确实有这个包,头文件在我在 json 文件中写的确切位置。如何将路径添加到编译器的搜索路径和链接器的搜索路径?
猜你喜欢
  • 2017-09-08
  • 2013-11-04
  • 2019-10-10
  • 2015-08-23
  • 2021-10-31
  • 1970-01-01
  • 2021-03-25
  • 2014-05-25
  • 2017-05-09
相关资源
最近更新 更多