Question

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.

Was it helpful?

Solution 3

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.

OTHER TIPS

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)

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top