0

If I search for files that include file libusb.h,

$grep -r "libusb.h" /usr/local/lib/

I get:

Binary file /usr/local/lib//libusb-1.0.0.dylib matches
Binary file /usr/local/lib//libusb-1.0.a matches
Binary file /usr/local/lib//libusb-1.0.dylib matches

But when I compile my class I get:

test.cpp:2:10: fatal error: 'libusb.h' file not found
#include <libusb.h>

Now I know this is because the /usr/local/lib folder isn't properly included. I tried things like the following, etc., but nothing seems to fix it.

gcc -lusb test.cpp
C_INCLUDE_PATH=/usr/local/lib
export C_INCLUDE_PATH

Update

Thanks to some of the help, I have come up with this command...

gcc test.cpp -I/usr/local/include -L/usr/local/lib -lusb-1.0

But now I get...

ld: symbol(s) not found for architecture x86_64

I tried adding

-stdlib=libstdc++

But that doesn't seem to help either.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jackie
  • 21,969
  • 32
  • 147
  • 289
  • 1
    You're just grepping binary data for libusb.h. You need to change your include paths in order to pick up the actual header file. – Soo Wei Tan Nov 29 '13 at 19:26
  • *[grep](http://linux.die.net/man/1/grep)* searches in the *content* of files, not for *file names*. Are you sure you did not intend to search for files named *libusb.h* in folder */usr/local/lib*? – Peter Mortensen Dec 01 '13 at 12:18

3 Answers3

2

Including the lib path won't help you here. The lib path contains the path of the binary files you link with.

You need to find the include path which provides the declarations for the exported symbols of the lib that you link against.

A common distribution (not set in stone!), is:

lib/       (binaries to link against)
include/   (declarations are here!)
bin/       (.so on *nix or .dll or Windows)
Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
  • Great so I see what you mean in the folder /usr/local/include/libusb-1.0/ I see the header-file. Could you possibly add the gcc command though (assuming the binaries are as described before). I tried using the gcc -l/usr/local/include/libusb-1.0 test.cpp and that didn't work. Sorry pretty new to all this. – Jackie Nov 29 '13 at 19:41
  • Alas, linux is not my forte, but isn't it something along the lines of `C_INCLUDE_PATH=/usr/local/include/libusb-1.0/`? I am sure someone else will let you know the exact way to do this. – Moo-Juice Nov 29 '13 at 19:43
  • gcc -I/usr/local/include/libusb-1.0 test.cpp works a little bit better but gives me "ld: symbol(s) not found for architecture x86_64" – Jackie Nov 29 '13 at 19:46
1

I may be beating a dead horse here. However I had the same issue and the solutions listed did not work for me. If you are in the same boat, this is what ended up working for me:

gcc -I /usr/include/libusb-1.0/ -lusb-1.0 example.c

SpyroSoft
  • 233
  • 1
  • 10
0

This works...

gcc -std=c++0x -stdlib=libc++ -I/usr/local/include -L/usr/local/lib -lusb-1.0 -lstdc++ test.cpp

You can also switch to Clang. This works:

clang++ -std=c++0x -stdlib=libc++ -I/usr/local/include -L/usr/local/lib -lusb-1.0 test.cpp

See comments for more information.

Jackie
  • 21,969
  • 32
  • 147
  • 289
  • 1
    If you actually post the full error message we can tell you what's wrong in the GCC case. – rubenvb Dec 01 '13 at 11:59
  • Will do a bit busy with the holiday will try to add that to the answer. – Jackie Dec 01 '13 at 22:29
  • And the exact command that gives that error? Try using g++ instead of gcc. – rubenvb Dec 02 '13 at 06:31
  • It is the one I list second in this answer, I will try g++ later but can't gcc compile c++? – Jackie Dec 02 '13 at 14:53
  • 1
    yes it can (`gcc` is just a compiler frontend, it tries to detect the input language through the filename's extension), but `g++`, when called to link, also pulls in the C++ standard library, which `gcc` does not do. If you want to link C++ object code which uses the standard library, you need to add `-lstdc++`. Using `g++` for C++ is just easier `;-)`. – rubenvb Dec 02 '13 at 15:29
  • Good work that does work when I add the -lstdc++. I like to clear the clouds and prevent obscurity even for the sake of convenience. – Jackie Dec 02 '13 at 21:07
  • using gcc instead of g++ is adding obscurity. What I described might not cut it in all situations and/or all platforms. Do what's right, not what you think is right based on very limited experience. – rubenvb Dec 02 '13 at 21:58
  • Ok but how is it less obscure if it is including other libs by default? – Jackie Dec 03 '13 at 02:34
  • I invite you to look at the verbose output of gcc and see hoe many libs are linked and what options are passed to ld without you knowing. You don't want to care, trust me. But do as you wish, I'm just trying to save you trouble. Your principle is flawed from the beginning,, that's all I'm saying... I'm not going to try and convince you further. – rubenvb Dec 03 '13 at 06:26