This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center




7年前关闭。




我正在尝试在Ubuntu 12.04下使用hidapi库。我已经按照github中的教程进行操作,但是,即使附带的测试代码也无法正常工作。它总是抱怨 undefined reference 。我找不到任何解决方案。即使成功安装后,我也无法在任何地方找到该库。

我正在尝试编译hidtest.cpp,第一个错误在hid_init()行中。

有人可以帮我吗?

编辑:
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

这是在Ubuntu 12.04下并使用Eclipse Juno完成的

最佳答案

这些是链接器错误:



最初我以为您没有将代码与hidapi库链接,但是我无意间设法重现了您的确切错误的唯一方法是将gcc参数的顺序错误。这将失败,输出相同:

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

您的目标文件需要在链接阶段的gcc参数中出现在库之前。

以下工作正常:
$ 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

请注意,我必须使用-I,-L和LD_LIBRARY_PATH,因为我没有安装hidapi,所以我做了hidapi源文件夹中的所有操作。

关于c++ - Hidapi无法在ubuntu下编译任何代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15433774/

10-11 20:38