Why does my libusb example end with runtime error

54 views Asked by At

I wanted to try out libusb under Linux. I was using one of there examples:

static void print_devs(libusb_device **devs)
{
    libusb_device *dev;
    int i = 0, j = 0;
    uint8_t path[8]; 

    while ((dev = devs[i++]) != NULL) {
        struct libusb_device_descriptor desc;
        int r = libusb_get_device_descriptor(dev, &desc);
        if (r < 0) {
            fprintf(stderr, "failed to get device descriptor");
            return;
        }

        printf("%04x:%04x (bus %d, device %d)",
            desc.idVendor, desc.idProduct,
            libusb_get_bus_number(dev), libusb_get_device_address(dev));

        r = libusb_get_port_numbers(dev, path, sizeof(path));
        if (r > 0) {
            printf(" path: %d", path[0]);
            for (j = 1; j < r; j++)
                printf(".%d", path[j]);
        }
        printf("\n");
    }
}


int main(int argc, char **argv)
{
    libusb_device **devs;
    int r;
    ssize_t cnt;

    r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);
    if (r < 0)
        return r;

    cnt = libusb_get_device_list(NULL, &devs);
    if (cnt < 0){
        libusb_exit(NULL);
        return (int) cnt;
    }
}

And I compiled it with: g++ -o main2 main2.cpp -llog4cpp -lcurl -lusb-1.0 It compiled without erros, but when I run it with ./main2 I get the following error ./main2: symbol lookup error: ./main2: undefined symbol: libusb_init_context What did I do wrong?

0

There are 0 answers