LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2011, 10:56 AM   #1
Sneezie
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Rep: Reputation: 0
Post Problem compiling a libusb program


Dear coders,
I am trying to compile a C program that includes the following code:

Code:
#include "libusb.h"

#define VENDOR_ID  0x0DE7
#define PRODUCT_ID 0x0191

#define CANT_SEND -1
#define CANT_READ -2


static struct usb_device *find_U401( struct usb_bus *bus )
    {

    struct usb_device *dev;

    /* look through all busses */
for (; bus; bus = bus->next )
        {
        /* look at every device  */
        for ( dev = bus->devices; dev; dev = dev->next )
            {
            /* match to known IDs  */
            if ( dev->descriptor.idVendor == VENDOR_ID && dev->descriptor.idProduct == PRODUCT_ID )
                {
                return dev;
                }
            }
        }
    return NULL;

}

[...]
I get from the gcc compiler the following error messages:

Quote:
usb@.c:10:45: warning: 'struct usb_bus' declared inside parameter list [enabled by default]
usb@.c:10:45: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
usb@.c: In function 'find_U401':
usb@.c:16:22: error: dereferencing pointer to incomplete type
usb@.c:19:24: error: dereferencing pointer to incomplete type
usb@.c:19:49: error: dereferencing pointer to incomplete type
usb@.c:22:21: error: dereferencing pointer to incomplete type
usb@.c:22:62: error: dereferencing pointer to incomplete type
The program is given by USBMicro as an example program to control under linux their circuits.

I have managed to get control under Windows, but that works invoking a DLL, a different story. I need to switch to linux, and actually in the end crosscompile it for an embedded PowerPC based linux system. But at the moment, in order to go in steps, just compiling for testing in a full Linux PC would be a progress...

I hope I have worked correctly the include dependencies with libusb, but the libusb test program compiles and runs fine.

I am a very basic C programmer, I am more in Fortran (!), Basic, Matlab environments and I am not fully understanding this program structure I have not written myself, therefore after many attempts and googleing I feel a bit helpless at the moment and I hope in a kick forward from you!

I understand it should lie in some missed variable declaration, but this were I stop...

I thank you in advance for any help!

Sneezie
 
Old 11-27-2011, 01:16 AM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

What linux distribution do you use? How did you install libusb?
In Ubuntu you can just
Code:
sudo apt-get install libusb-dev
After that this program (which looks similar to yours) compiles if you change #include to
Code:
#include <usb.h>
`usb.h' is the only header file that comes with `libusb-dev':
Code:
$ dpkg -L libusb-dev  | grep .h$
/usr/include/usb.h
Don't forget to link your program against libusb:
Code:
gcc test.c -lusb
Hope this helps.

Last edited by firstfire; 11-27-2011 at 01:21 AM.
 
1 members found this post helpful.
Old 11-27-2011, 05:17 AM   #3
Sneezie
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you firstfire!

Quote:
Originally Posted by firstfire View Post

What linux distribution do you use? How did you install libusb?
I am using Ubuntu 11.
Actually, I have already installed libusb, both by apt-get (as a second smarter move) and (firstly) by compiling the downloaded distribution (can this have messed things a bit?).

It seems it got installed in /usr/local/lib, which I added to lib.so.conf and then I run ldconfig.

I was actually including libusb, since with usb I got referencing error messages for the send_message command. And then in the search of some solution I tried to include libusb and got stuck with it, since it was also compiling fine the example program of the libusb library.

Your suggestion has therefore solved the original problem I posted, but now if I include lines including the "send_message" command, which are in the rest of the program I have not posted to the forum, I get the errors:

Code:
usb@.c:(.text+0x1fb): undefined reference to `send_command'
The other commands related to USB management in the test program seem to compile fine when I take away the `send_command' statements.

Therefore, it seems this time the problem lies in the dependencies to libusb which are not correctly addressed.
You managed to compile the program from the USBMicro site, if I understood well, therefore the problem is on my side, I reckon...
I am (have been) working on that, but if you have a hint, I would be grateful!

I bet the crosscompiling step will be even tougher (I already managed to crosscompile with buildroot other programs on a couple of platforms, but libusb so far is the one giving me headaches... I am not 'that' experienced and when things get bumpy for any reason I get lost).

Thank you again!

Sneezie
 
Old 11-27-2011, 05:57 AM   #4
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

Could you please post complete code and gcc command line?

Your last error message looks strange because function `send_command' is defined in the code I compiled:
Code:
int send_command( struct usb_dev_handle *handle, char *command, int comLen, int resLen )
{

    int ret = usb_control_msg( handle, 0x21, 9, 0x0200, 0, command, comLen, 5000 );

    // check that send was successful
    if ( ret != comLen )
        return CANT_SEND;

    // does the command expect a result?
    if ( resLen > 0 )
        {
        ret = usb_bulk_read( handle, 0x81, command, resLen, 5000 );
        if ( ret != resLen )
            return CANT_READ;

        }

    return ret;

}
 
Old 11-27-2011, 06:35 AM   #5
Sneezie
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by firstfire View Post
Hi.
Your last error message looks strange because function `send_command' is defined in the code I compiled:
Bingo!

I was trying compiling the code in chunks and I forgot to put the send_command definition back in place!

Obviously the compiler was complaining!

Compilation successful!

On to the crosscompiler now!

I think I tried all the combinations, but once I got in trouble I began to swirl in nonsense...
You put all pieces in the right order!

Thank you really very much!

Sneezie

P.S.-Unfortunately this is not a promise that I will not get into trouble again...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
the program hang when executing libusb-init,why? viktor2000 Linux - Newbie 1 10-18-2011 06:00 AM
Compiling libusb c++ program to run without it's dependencies linuxmandrake Programming 10 08-06-2010 08:09 PM
compiling/install libusb O(V)eGA_l2el) Fedora 2 05-13-2005 11:19 AM
hpoj and libusb compiling problems jonman364 Linux - Software 1 11-09-2004 04:38 PM
Problem with compiling my program. Zeth_htp Linux - Newbie 4 04-04-2003 10:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration