PDA

View Full Version : Undefined reference when including lib



Baasie
1st October 2009, 12:03
Greetings fellow QT's.

with my question i need to tell you some info.

first of all i am making a program that can communicate with a mp3 player trough MTP. Now there are some handy lib packages on the web called libmtp wich makes use of libusb and libiconv.

All in all got these on my pc. Now someone already made a QT program called qlix wich does the same and found code in this program.

Now i already posted about linking hte libs into my program and got an answer i needed to use INCLUDEPATH into my pro file where the header files are. I did this and it compiles it good.

Now i just want to use 1 line to initialize libmtp like that other program does and what the documentation does, but it gives me an error.

the code atm is simple:

LIBMTP_INIT();

and trough that i get

release/widget.o:widget.cpp::-1: error: undefined reference to `LIBMTP_Init'


now i checked the internet for an answer but i did not get the real answer i need so that is why i come back to this forum.

so can anyone help me with the problem and isn;t it better to include the 3 packages into mingw32 ?... and if so how do it do this ?

thanx in advance

_baasie

scascio
1st October 2009, 12:12
You are facing a link error.
Just add in your .pro the path to your lib and its name with :

LIBS += -L<path_to_the_lib> -l<libName>

Baasie
1st October 2009, 14:04
thanx a bunch this helped a lot :)

sisco
22nd October 2009, 14:07
You are facing a link error.
Just add in your .pro the path to your lib and its name with :

LIBS += -L<path_to_the_lib> -l<libName>

so how would i do this when i want to use libusb? i downloaded the package from the website and followed the instructions in the install file. now how can i set up my QT creator project to make use of libusb?

i put the libusb folder with all the .o files in my project folder and added this line to my project file:

LIBS += -Llibusb -l libusb

but compiling gives me this error:


mainwindow.o: In function `MainWindow':
/home/sisco/Projects/USBCom/mainwindow.cpp:9: undefined reference to `libusb_init'
/home/sisco/Projects/USBCom/mainwindow.cpp:9: undefined reference to `libusb_init'
collect2: ld returned 1 exit status
make: *** [USBCom] Error 1
Exited with code 2.
Error while building project USBCom
When executing build step 'Make'

thanks,


Sisco

Baasie
22nd October 2009, 16:03
i think i placed the include files into include the .a files into the lib and you should have gotten .dll files to... place those into your system32 folder and then it should work i think...

i bitched a lot and need to retrace what i exacly did in the end..

if this doesn't work i will try it for you on a VB soon..

regards Baasie

edit: this is my .pro entry



LIBS += -LC:/Qt/mingw/lib \
-llibmtp \
libusb \
libiconv \
libtag


edit2: don't forgot to place this in your header:



#include <usb.h>

sisco
23rd October 2009, 09:29
i think i placed the include files into include the .a files into the lib and you should have gotten .dll files to... place those into your system32 folder and then it should work i think...

i bitched a lot and need to retrace what i exacly did in the end..

if this doesn't work i will try it for you on a VB soon..

regards Baasie

edit: this is my .pro entry



LIBS += -LC:/Qt/mingw/lib \
-llibmtp \
libusb \
libiconv \
libtag


edit2: don't forgot to place this in your header:



#include <usb.h>


i am running linux and dont have any .dll files after running the setup the libs were installed /use/local/lib

but when adding this to my .pro file
LIBS += -L/usr/local/lib \ -llibusb


#include </usr/local/include/libusb-1.0/libusb.h>

while compiling gives me an error


g++ -m64 -Wl,-rpath,/home/sisco/qtsdk-2009.04/qt/lib -o USBCom main.o mainwindow.o moc_mainwindow.o -L/home/sisco/qtsdk-2009.04/qt/lib -L/usr/local/lib \ -llibusb -lQtGui -L/home/sisco/qtsdk-2009.04/qt/lib -L/usr/X11R6/lib64 -pthread -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lfontconfig -lXext -lX11 -lQtCore -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
g++: -llibusb: No such file or directory
make: Leaving directory `/home/sisco/Projects/USBCom'
make: *** [USBCom] Error 1
Exited with code 2.
Error while building project USBCom
When executing build step 'Make'

i dont know what im doing wrong, seems like i have set everything up right.

Baasie
27th October 2009, 08:19
Unfort i dunno much about linux....

and i did not have that error poorly :(

DmitryNik
30th January 2013, 19:03
Since year 2009 nobody answered on this thread, OK. I encountered with this problem as it is only several minutes ago though. My solution for this problem was pretty easy:


INCLUDEPATH += "/usr/local/include/libusb-1.0"
LIBS += "/usr/local/lib/libusb-1.0.a"

Hope this will help someone else too=)

p.s. Also, this could be used as well:


INCLUDEPATH += "/usr/local/include/libusb-1.0"
LIBS += -L"/usr/local/lib" -lusb-1.0

jvk
29th December 2013, 15:26
Thanks DmitryNik, I've been searching for a solution for the past few hours and yours worked perfectly.