Results 1 to 9 of 9

Thread: Undefined reference when including lib

  1. #1
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default Undefined reference when including lib

    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

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference when including lib

    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>

  3. #3
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default Re: Undefined reference when including lib

    thanx a bunch this helped a lot

  4. #4
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    4

    Default Re: Undefined reference when including lib

    Quote Originally Posted by scascio View Post
    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:

    Qt Code:
    1. mainwindow.o: In function `MainWindow':
    2. /home/sisco/Projects/USBCom/mainwindow.cpp:9: undefined reference to `libusb_init'
    3. /home/sisco/Projects/USBCom/mainwindow.cpp:9: undefined reference to `libusb_init'
    4. collect2: ld returned 1 exit status
    5. make: *** [USBCom] Error 1
    6. Exited with code 2.
    7. Error while building project USBCom
    8. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

    thanks,


    Sisco

  5. #5
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default Re: Undefined reference when including lib

    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

    Qt Code:
    1. LIBS += -LC:/Qt/mingw/lib \
    2. -llibmtp \
    3. libusb \
    4. libiconv \
    5. libtag
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. #include <usb.h>
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    4

    Default Re: Undefined reference when including lib

    Quote Originally Posted by Baasie View Post
    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

    Qt Code:
    1. LIBS += -LC:/Qt/mingw/lib \
    2. -llibmtp \
    3. libusb \
    4. libiconv \
    5. libtag
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. #include <usb.h>
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. LIBS += -L/usr/local/lib \ -llibusb
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include </usr/local/include/libusb-1.0/libusb.h>
    To copy to clipboard, switch view to plain text mode 

    while compiling gives me an error

    Qt Code:
    1. 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
    2. g++: -llibusb: No such file or directory
    3. make: Leaving directory `/home/sisco/Projects/USBCom'
    4. make: *** [USBCom] Error 1
    5. Exited with code 2.
    6. Error while building project USBCom
    7. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

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

  7. #7
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default Re: Undefined reference when including lib

    Unfort i dunno much about linux....

    and i did not have that error poorly

  8. #8
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Lightbulb Re: Undefined reference when including lib

    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:

    Qt Code:
    1. INCLUDEPATH += "/usr/local/include/libusb-1.0"
    2. LIBS += "/usr/local/lib/libusb-1.0.a"
    To copy to clipboard, switch view to plain text mode 

    Hope this will help someone else too=)

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

    Qt Code:
    1. INCLUDEPATH += "/usr/local/include/libusb-1.0"
    2. LIBS += -L"/usr/local/lib" -lusb-1.0
    To copy to clipboard, switch view to plain text mode 
    Last edited by DmitryNik; 30th January 2013 at 18:23.

  9. #9
    Join Date
    Mar 2013
    Posts
    2

    Default Re: Undefined reference when including lib

    Thanks DmitryNik, I've been searching for a solution for the past few hours and yours worked perfectly.

Similar Threads

  1. xerces - undefined reference
    By eleanor in forum General Programming
    Replies: 3
    Last Post: 27th April 2009, 13:16
  2. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  3. MS Sql native driver??
    By LordQt in forum Qt Programming
    Replies: 4
    Last Post: 9th October 2007, 13:41
  4. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  5. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.