Thread: libusb headache

  1. #1
    Registered User
    Join Date
    Dec 2008

    libusb headache


    First post, so do be gentle.

    I am trying to get libusb to work w/ my compiler and all seems fine until I try something like:

    #include <usb.h>
    int main(int argc, char **argv) {
    	struct usb_bus *busses;
       	busses = usb_get_busses();
    	return 0;
    I'm on Ubuntu 8.04 (Hardy Heron), and using Eclipse 3.2.2. I can compile other C code just fine (having a great time w/ GTK+). I can see that usb.h is in my `Includes` folder i.e., `/usr/include/usb.h` but I get a bunch of messages when I attempt to compile like:

    undefined reference to `usb_init'
    I guess it is something to do w/ the Linker as that is where the error gets thrown (see below). But how would I go about resolving that?

    **** Build of configuration Debug for project usb ****
    make -k all 
    Building file: ../main.c
    Invoking: GCC C Compiler
    gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.c"
    Finished building: ../main.c
    Building target: usb
    Invoking: GCC C Linker
    gcc  -o"usb"  ./main.o   
    ./main.o: In function `main':
    /home/cbee/c/usb/Debug/../main.c:6: undefined reference to `usb_init'
    /home/cbee/c/usb/Debug/../main.c:7: undefined reference to `usb_find_busses'
    /home/cbee/c/usb/Debug/../main.c:8: undefined reference to `usb_find_devices'
    /home/cbee/c/usb/Debug/../main.c:9: undefined reference to `usb_get_busses'
    collect2: ld returned 1 exit status
    make: *** [usb] Error 1
    make: Target `all' not remade because of errors.
    Build complete for project usb

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Sometimes these things require additional options to gcc, as with gtk+ and pkg-config. I've never used libusb tho, so I don't know.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Dec 2008
    Yep, I resolved it of course almost after my post.

    Here is the solution w/ screenshots:

    Thank you to anyone who spent time looking and thinking it out on my behalf.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Header File Headache
    By Bladactania in forum C Programming
    Replies: 12
    Last Post: 02-11-2009, 06:54 AM
  2. API Thread HEADACHE
    By WaterNut in forum Windows Programming
    Replies: 11
    Last Post: 01-16-2007, 10:10 AM
  3. I/O headache
    By Strait in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2005, 12:20 PM
  4. My headache
    By Morgan in forum C Programming
    Replies: 7
    Last Post: 12-03-2002, 03:33 AM
  5. Linked List headache
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 09-23-2001, 06:42 PM

Tags for this Thread