如何重新编译现有的Linux应用程序

时间:2015-11-04 18:05:25

标签: linux makefile bluetooth-lowenergy

我希望编辑并重新编译bluez版本5.31的hcitool.c。我按照以下步骤安装了bluez 5.31: Bluetooth Low Energy in C - using Bluez to create a GATT server

在我的试用版中,我复制了hcitool.c文件并在tools文件夹中将其命名为myhcitool.c并使用命令

gcc -o myhcitool.o myhcitool.c. 

这给了我一个错误

myhcitool.c:43:27: fatal error: lib/bluetooth.h: No such file or    directory
 #include "lib/bluetooth.h"
                       ^
compilation terminated.

我尝试将myhcitool.c复制到tools文件夹之外并在那里编译。这给了我一堆像这样的错误:

/tmp/ccj1QmZK.o: In function `dev_info':
myhcitool.c:(.text+0x293): undefined reference to `ba2str'
/tmp/ccj1QmZK.o: In function `conn_list':
myhcitool.c:(.text+0x501): undefined reference to `ba2str'
myhcitool.c:(.text+0x50f): undefined reference to `hci_lmtostr'
myhcitool.c:(.text+0x586): undefined reference to `bt_free'
/tmp/ccj1QmZK.o: In function `cmd_dev':

我还尝试通过在那里修改一个简单的printf来编辑hcitool.c本身,然后为整个bluez重做'make'和'make install'命令。之后,当我尝试运行hcitool时,我所做的修改没有效果。

1 个答案:

答案 0 :(得分:1)

编译错误清楚地表明您缺少文件和目录,并且存在未定义的类型引用(因为您缺少文件)。您正在复制其目录之外的文件并尝试编译它。这不会起作用,因为缺少正确编译所需的包含(以及更多)。

  • 如果您想直接编辑hcitool,您应该下载Bluez源代码,将其解压缩,cd并将其./configure。将生成makefile,您可以使用make来构建可执行文件。如果你对hcitool.c文件进行了更改,你应该确保你重新编译它并在目录./hcitool内运行它而不是通用hcitool,因为它运行安装到你系统的可执行文件,而不是比你编辑的那个。

  • 如果您想在Bluez目录之外构建它作为一种独立的,您必须复制所需的#include <x>语句中定义的所有文件和文件夹,并制作单独的makefile对于那些,因为复制现有的可能不会起作用。

  • 如果要向Bluez源添加新文件,请确保您还编辑了正确的Makefile,以便在编译期间包含它。

我想补充说,hcitool已经很长时间没有维护,并且正在逐步退出Bluez,所以也许你应该采取不同的方法!