-1

I am writing a program in QT in C++. I am using the library libusb.h. Below is my code -

libusb_device **devs;
libusb_device_handle *dev_handle;
libusb_context *ctx = NULL;
int r;
ssize_t cnt; 
r = libusb_init(&ctx); 
if(r < 0) {
        cout<<"Init Error "<<r<<endl; //there was an error
        return 1;
    }

But when I want to build it, the errors is occur.

/home/test/main.cpp:12: błąd: undefined reference to `libusb_init'

This is file.pro

QT += core
QT -= gui

TARGET = test
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

Can someone help me pointing out the mistake in my code above?

P.Wujek
  • 1
  • 1

2 Answers2

1

That's a link error.

Add the following to your project (.pro) file. Do not forget to edit library path and library name according to your own setup.

INCLUDEPATH += "/usr/local/include/libusb-1.0"
LIBS += -L"/usr/lib" -l"usb-1.0"
0

You didn't

#include "libusb.h"

or

#include <libusb.h>
Goswin von Brederlow
  • 11,875
  • 2
  • 24
  • 42