how to us lib usb in c++ - visual-c++

i want to communicate with usb port in c++. i know the libusb is a good way, but i can't use it. i have downloaded many libusb versions, for example libusbx-1.0.12.tar,libusb-win32-bin-1.2.6.0,libusb-1.0.9.tar. but i have many problem with them. for example there is a header file in them i have made a project then add libusb.h to header files and use #include command in to the c++ empty project bud this command is unspacified. is ther any one here to help me, i want a step by step and complete instruction to use libusb.

You should start with libusb-win32
and read their wiki very carefully.
Including a header file is not sufficient. You also need to link with the import library (which is a standard action you need to take when using 3th party libraries, and is unrelated to libusb)

Related

Is there a directory where i can put a d file so that the compiler automatically includes it?

I am new to the D programming language, and would like to use ncurses in D. I have found a good D port of ncurses, but I want to be able to import it in any source file without writing:
gdc <files> ncurses.d
Is there any way I can make it included every time?
Btw I am using gdc on debian Gnu/Linux.
No. You should consider using a build tool, such as rdmd, which will automatically construct a compiler's command line and add all modules included by your program.
If, for some reason, you don't want to use a build tool, a common approach is to use a Makefile.

Can configure generate .h files?

On Linux, when I execute ./configure it generates header files and also .c files (besides Makefiles), right? How can I get configure to do that?
You will probably want to create a configure.ac (but depend on the autoconf version), but read here, to give you an idea what should you create and what is auto generated. It has good covered on the autotools topic.
It's typically used to generate config header, that contains various defines (often libraries & function present or not). But this happens only if autotools were instructed to create configure doing that.
You define what goes to (and to which header exactly) in configure.ac (input file to autotools). See AC_CONFIG_HEADERS, AC_CHECK_HEADER, AC_CHECK_LIB and similar macros. See autoconf manual for details. Also read through complete tutorial jasonw linked. And see how things are done in some existing projects.

problem with unistd.h in VC++

It always produce an error that cant find "unistd.h" why? Any remedies for this?
Services for Unix ships with various linux related headers (including unistd.h), so you could use that.
But that might require to link some of the SFU libraries..
Why? It's just not there. It looks like you try to compile a program that is not portable or you try to port the program to Windows.
unistd.h is a not a standard header. Probably you find it only on Unix-like systems.
See: Wiki
See Is there a replacement for unistd.h for Windows (Visual C)? for a partial replacement. (If you can add aditional functionality, please do so).

How to get a configure script to look for a library

I'm trying to write a configure.ac file such that the resulting configure script searches for a library directory containing a given static library e.g. libsomething.a. How can I do this? At the moment I have it check just one location with:
AC_CHECK_FILE([/usr/local/lib/libsomething.a],[AC_SUBST(libsomething,"-L/usr/local/lib -lsomething")],[AC_SUBST(libcfitsio,'')])
But I want it to try and find it automatically. And if the library isn't in one of the default locations, I'd like configure to say that the library wasn't found and that a custom location can be specified with --use-something=path as is usually done. So I also need to then check if --use-something=path is provided. I'm pretty new at creating configure files, and the M4 documentation isn't very easy to follow, so would appreciate any help.
Thanks!
It's not the job of configure to search where libraries are installed. it should only make sure they are available to the linker. If the user installed them in a different location, he knows how to call ./configure CPPFLAGS=-I/the/location/include LDFLAGS=-L/the/location/lib so that the tools will find the library (this is explained in the --help output of configure and in the standard INSTALL file).
Also --with-package and --enable-package macros are not supposed to be used to specify paths, contrary to what many third-party macros will do. The GNU Coding Standards explicitly prohibit this usage:
Do not use a --with option to
specify the file name to use to find
certain files. That is outside the scope
of what --with options are for.
CPPFLAGS and LDFLAGS are already here to address the problem, so why redevelop and maintain another mechanism?
The best way to figure this out is to look at other autoconf macros that do something similar. Autoconf macros are an amalgam of Bourne shell script and M4 code, so they can literally solve any computable problem.
Here's a link to a macro I wrote for MySQL++ that does this: mysql++.m4.

How to convert a makefile into readable code?

I downloaded a set of source code for a program in a book and I got a makefile.
I am quite new to Linux, and I want to know whether there is any way I can see the actual source code written in C?
Or what exactly am I to do with it?
It sounds like you may not have downloaded the complete source code from the book web site. As mentioned previously, a Makefile is only the instructions for building the source code, and the source code is normally found in additional files with names ending in .c and .h. Perhaps you could look around the book web site for more files to download?
Or, since presumably the book web site is public, let us know which one it is and somebody will be happy to point you in the right direction.
A Makefile does not contain any source itself. It is simply a list of instructions in a special format which specifies what commands should be run, and in what order, to build your program. If you want to see where the source is, your Makefile will likely contain many "filename.c"'s and "filename.h"'s. You can use grep to find all the instances of ".c" and ".h" in the file, which should correspond to the C source and header files in the project. The following command should do the trick:
grep -e '\.[ch]' Makefile
To use the Makefile to build your project, simply typing make should do something reasonable. If that doesn't do what you want, look for unindented lines ending in a colon; these are target names, and represent different arguments you can specify after "make" to build a particular part of your project, or build it in a certain way. For instance, make install, make all, and make debug are common targets.
You probably have GNU Make on your system; much more information on Makefiles can be found here.
It looks like you also need to download the SB-AllSource.zip file. Then use make (with the Makefile that you've already downloaded) to build.

Resources