C编译debian错误

时间:2015-02-17 14:06:14

标签: c linux ubuntu debian raspberry-pi

我正在尝试在Debian(Raspberry Pi Raspbian)上编译一个C程序ipad_charge(https://github.com/mkorenkov/ipad_charge)。它是为Ubuntu编写的,我在那里安装它没有任何问题。在Debian上,我得到编译错误;

gcc -Wall -Wextra ipad_charge.c -lusb-1.0 -o ipad_charge
ipad_charge.c: In function ‘set_charging_mode’:
ipad_charge.c:37:3: warning: implicit declaration of function ‘libusb_strerror’ [-Wimplicit-function-declaration]
ipad_charge.c:37:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat]
ipad_charge.c:43:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat]
ipad_charge.c:53:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat]
ipad_charge.c: In function ‘main’:
ipad_charge.c:152:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat]
/tmp/cc1hdopk.o: In function `set_charging_mode':
ipad_charge.c:(.text+0x6c): undefined reference to `libusb_strerror'
ipad_charge.c:(.text+0xe0): undefined reference to `libusb_strerror'
ipad_charge.c:(.text+0x18c): undefined reference to `libusb_strerror'
/tmp/cc1hdopk.o: In function `main':
ipad_charge.c:(.text+0x5fc): undefined reference to `libusb_strerror'
collect2: ld returned 1 exit status
Makefile:2: recipe for target 'ipad_charge' failed
make: *** [ipad_charge] Error 1

当我查看代码时,似乎libusb正在进行繁重的工作。我的猜测是我需要运行一个更新的libusb版本才能在Debian上编译。既然我想继续使用Debian stable,有人知道如何在Debian中安装更新版本的libusb,这样我才能让这个程序运行起来吗?我是否正确理解了问题,还是存在其他问题?

1 个答案:

答案 0 :(得分:1)

您可以下载source code of libusb,进行编译并安装(例如在/usr/local/中),然后使用

编译ipad_charge.c
  gcc -Wall -Wextra -O -g -v -H -I/usr/local/include/ -L /usr/local/lib \
       ipad_charge.c -lusb-1.0 -o ipad_charge

请确保-H告诉您使用了正确的包含文件(在/usr/local/中),-v(甚至可能是-Wl,-v)告诉您正确的库(在/usr/local/中)被使用。