【问题标题】:C compiling errors on debianDebian上的C编译错误
【发布时间】:2015-02-17 14:06:14
【问题描述】:

我正在尝试在 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 以便我可以让这个程序工作吗?我是否正确理解了这个问题,还是有其他问题?

【问题讨论】:

    标签: c linux ubuntu debian raspberry-pi


    【解决方案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/ 中)被使用了。

    【讨论】:

    • 嗨 Basile - 安装说明是运行 sudo apt-get install libusb-1.0-0 libusb-1.0-0-dev git clone github.com/mkorenkov/ipad_charge.git cd ipad_charge/ make sudo make install 所以实际编译发生在运行 make 之后。如何告诉 gcc 使用正确的包含文件?
    • 您好 Basile - 感谢您的回复。我不习惯下载源和编译,所以谢谢你的解释。我现在明白我需要在 makefile 中编辑 gcc 编译语句以引用 /usr/local/lib,但是当我使用你的语句时它不起作用。你的意思是在上面的“/usr/local/lib”后面加一个反斜杠吗?
    • 终止的反斜杠使两个物理行成为一个命令行。显然,您需要首先熟悉命令行。您是否在笔记本电脑上安装了 Linux?
    • 感谢您的帮助,巴西尔。这不是编译问题,看来我需要更新的 libusb。现在一切正常。
    猜你喜欢
    • 2013-05-07
    • 2016-05-17
    • 2018-02-27
    • 2013-05-22
    • 1970-01-01
    • 2012-07-10
    • 1970-01-01
    • 2019-07-04
    • 2019-12-29
    相关资源
    最近更新 更多