Re: using libusb

Discussion in 'C Programming' started by James Kuyper, Aug 21, 2012.

  1. James Kuyper

    James Kuyper Guest

    On 08/21/2012 03:44 PM, mahnaz0098 wrote:
    > Hello
    > I need to communicate with USB port by C. I found a comppresd (.rar) file. Its name is libusb-win32-bin- I extracted it and it contains several files and header file(lusb0_usb) and some example programs to communicate via USB .
    > I added lusb0_usb.h to this program (right click on Header Files in solution explorer and choose add > existing item then browse lusb0_usb.h),
    > (#include <lusb0_usb.h> ). I can't debug this example program. Do I need to do another action to add this new library (lusb0_usb.h) to use in this program?
    > i use visual C++ and it shows me this error:
    > Error 1 fatal error C1083: Cannot open include file: 'lusb0_usb.h': No such file or directory c:\users\...\usb\usb.c

    Your question is primarily about a particular library, and should be
    directed to someone who knows something about that particular library.

    However, some aspects of your question are purely C related, and I can
    address those:

    The thing that's brought into your code by using #include is called a
    header file, not a library file. The fact that the compiler can't open
    that file has nothing to do with the library. When your code gets
    linked, you will have to tell the compiler the correct location where it
    can find the corresponding library file, but this compilation has failed
    before that question has even come up.

    There's a list of locations that the compiler is supposed to search when
    you use

    #include <lusb0_usb.h>

    That list of locations can, in principle, be quite different for each
    implementation of C, but it always includes whatever location the
    standard headers are stored in (even if they're not stored in a
    directory). That's why you should use #include <> for standard headers.
    For the particular compiler you're using, the default list of locations
    apparently does not include whichever directory you've currently got
    lusb0_usb.h in.

    If you were to use

    #include "lusb0_usb.h"

    there might or might not be a different list of locations your compiler
    will search for the file - that's up to your compiler. However, it's
    fairly commonplace for the list to include the current directory, or the
    same directory that the source code file was located in. However, if it
    can't find the file in one of those locations, it will then search the
    same locations it would have searched if you had written #include
    <lusb0_usb.h>. Because it might cause your compiler to search additional
    locations, you should generally use #include "" for headers that are not
    part of the C standard.

    If changing from #include <> to #include "" doesn't solve your problem,
    I'd recommend reading solution explorer's documentation to find out what
    locations are searched by default, and how you can control which
    locations get searched. In my development environment, it's controlled
    by -I command line options passed to the compiler, but you're working in
    a very different environment, so the correct way to do it might be quite
    James Kuyper, Aug 21, 2012
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William F. Robertson, Jr.
    Kathy Burke
    Jun 25, 2003
  2. pete
    Jon Yates
    Aug 29, 2003
  3. timmso
    Alex Papadimoulis
    Dec 12, 2003
  4. Replies:
  5. Johann Klammer

    Re: using libusb

    Johann Klammer, Aug 21, 2012, in forum: C Programming
    Johann Klammer
    Aug 21, 2012

Share This Page