Question

I am trying to use the hidapi library under Ubuntu 12.04. I have followed the tutorial in github, however, not even the test code that comes with it is working. It always complains about undefined reference. I cannot find any solution. I cannot find the library any where, even after a successful installation.

I'm trying to compile the hidtest.cpp, the first error is in the hid_init() line.

Could someone help me?

EDIT:

make all 

Building target: hidtest

Invoking: Cross G++ Linker

g++  -o "hidtest"  ./src/hidtest.o   

./src/hidtest.o: In function `main':
/../src/hidtest.cpp:35: undefined reference to `hid_init'
/../src/hidtest.cpp:38: undefined reference to `hid_enumerate'
/../src/hidtest.cpp:53: undefined reference to `hid_free_enumeration'
/../src/hidtest.cpp:63: undefined reference to `hid_open'
/../src/hidtest.cpp:71: undefined reference to `hid_get_manufacturer_string'
/../src/hidtest.cpp:78: undefined reference to `hid_get_product_string'
/../src/hidtest.cpp:85: undefined reference to `hid_get_serial_number_string'
/../src/hidtest.cpp:93: undefined reference to `hid_get_indexed_string'
/../src/hidtest.cpp:99: undefined reference to `hid_set_nonblocking'
/../src/hidtest.cpp:103: undefined reference to `hid_read'
/../src/hidtest.cpp:111: undefined reference to `hid_send_feature_report'
/../src/hidtest.cpp:120: undefined reference to `hid_get_feature_report'
/../src/hidtest.cpp:123: undefined reference to `hid_error'
/../src/hidtest.cpp:137: undefined reference to `hid_write'
/../src/hidtest.cpp:140: undefined reference to `hid_error'
/../src/hidtest.cpp:146: undefined reference to `hid_write'
/../src/hidtest.cpp:155: undefined reference to `hid_read'
/../src/hidtest.cpp:173: undefined reference to `hid_close'
/../src/hidtest.cpp:176: undefined reference to `hid_exit'

collect2: ld returned 1 exit status

make: *** [hidtest] Error 1

This is done under Ubuntu 12.04 and using Eclipse Juno

Was it helpful?

Solution

Those are linker errors :

collect2: ld returned 1 exit status

I initially thought that you were not linking your code with the hidapi library, but the only way I accidentally managed to reproduce the exact errors you had was by putting the gcc parameters in the wrong order. This fails with the same output :

$ g++ -c -Ihidapi hidtest/hidtest.cpp -o hidtest/hidtest.o
$ g++ -Llinux/.libs -lhidapi-hidraw hidtest/hidtest.o -o test

Your object file needs to appear before the library in the gcc arguments for the linking stage.

The following works just fine :

$ g++ -c -Ihidapi hidtest/hidtest.cpp -o hidtest/hidtest.o
$ g++ -Llinux/.libs hidtest/hidtest.o -lhidapi-hidraw -o test
$ LD_LIBRARY_PATH=linux/.libs ./test

Note that I have to use -I, -L and LD_LIBRARY_PATH because I did not install hidapi, I did everything from the hidapi source folder.

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