0

I am working on Visual Studio Code on Windows 7 64-bit. After searching online for quite a while, I still can't solve my problem: I have a C program that includes libusb.h. whenever I try to compile using gcc, I get the following error:

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.

I tried a few solutions online, changing c_cpp_properties.json and settings.json(causing to VSCode to not showing any error on the #include <libusb.h> line).

here is my files: 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"
]
}

I am pretty lost after hours on this problem, I would appreciate any help.

EDIT: This the the complete output of the following command: gcc min.c -o min where min.c is the only C file I have.

Orel Vaknin
  • 35
  • 1
  • 8
  • I'll ask just in case. Does your program consist of a single .c file? – HolyBlackCat Jun 21 '20 at 20:22
  • Are you _sure_ there's a `libusb.h` at that path? For me it's under `libusb-1.0.23\include\libusb-1.0` – DaV Jun 21 '20 at 20:29
  • @HolyBlackCat yes it is a single c file. – Orel Vaknin Jun 21 '20 at 21:07
  • @DaV sorry it is the wrong path, I will fix it in the question. the problem still remains. – Orel Vaknin Jun 21 '20 at 21:08
  • 1
    Then either there's no libusb.h there, or the compiler doesn't know to search that path. Please attach the full build output to your question, including what exactly is passed to GCC. – DaV Jun 21 '20 at 22:19
  • 1
    Also as you're on windows, you may need to specify the build path with escaped backslashes: `"C:\\Users\\VAKNIN\\Downloads\\Orel-thesis\\libusb-1.0.23\\include\\libusb-1.0"` – DaV Jun 21 '20 at 22:23
  • @DaV I tried using escaped backslashes, still no change. this is the complete output I get from gcc. – Orel Vaknin Jun 22 '20 at 09:05

1 Answers1

0

Find the location of your libusb, or if you don't have it get it from http://libusb.info/ and build it, or get a prebuilt package matching your system (win32 or win64).

Then make sure your compiler's search path includes the path of the include folder where libusb.h is, and the linker's search path includes the path where the library is.

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
  • I do have the package, the header file is in the exact location I wrote in the json files. How could I add the path to the compiler's search path and the linker\s search path? – Orel Vaknin Jun 22 '20 at 10:11
  • See: https://stackoverflow.com/questions/57173093/how-to-include-compiler-flags-in-the-visual-studio-code-debugger – Brecht Sanders Jun 22 '20 at 11:44