首页 > 解决方案 > 包含路径不适用于 Bluez 库

问题描述

我正在尝试使用 Linux 上的 Bluez 库在 C 中开发应用程序。我不知道如何正确地将所有包含路径传递给编译器,以便我需要的所有库都可见。

无论我尝试什么,我都会收到以下错误:

cc -g -I<PATH_TO_BLUEZ>/bluez-5.54/ -I/usr/include/glib-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ -ldbus-1 -ldbus-glib-1     -c -o disc_gdbus.o disc_gdbus.c
cc -o myprog disc_gdbus.o -I<PATH_TO_BLUEZ>/bluez-5.54/ -I/usr/include/glib-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ -ldbus-1 -ldbus-glib-1 
disc_gdbus.o: In function `print_chrc':
<PATH_TO_APP>/disc_gdbus.c:98: undefined reference to `bt_uuidstr_to_str'
disc_gdbus.o: In function `print_desc':
<PATH_TO_APP>/disc_gdbus.c:120: undefined reference to `bt_uuidstr_to_str'
collect2: error: ld returned 1 exit status
Makefile:15: recipe for target 'myprog' failed
make: *** [myprog] Error 1

我需要包括以下文件:

#include <glib.h>
#include "src/shared/util.h"
#include "src/shared/queue.h"
#include "src/shared/io.h"
#include "src/shared/shell.h"
#include "gdbus/gdbus.h"

函数 bt_uuidstr_to_str 在目录中<PATH_TO_BLUEZ>/bluez-5.54/src/shared/util.h。所以应该看到。

在makefile中,我包含了这样的所有内容:

INC=-I<PATH_TO_BLUEZ>/bluez-5.54/ \
    -I/usr/include/glib-2.0 \
    -I/usr/include/dbus-1.0 \
    -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/ \
    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ \
    -ldbus-1 \
    -ldbus-glib-1 \

src = disc_gdbus.c
obj = $(src:.c=.o)

CFLAGS=-g $(INC) $(LIBS)

myprog: $(obj)
    $(CC) -o $@ $^ $(CFLAGS)

.PHONY: clean
clean:
    rm -f $(obj) myprog

我研究了修改包含路径的方法,这种方法应该允许链接器查看所有相关文件,但不知何故它没有。我提供了那些包含 VS Code 的路径,它们可以正常工作:

{
"C_Cpp.default.includePath": [
    "<PATH_TO_BLUEZ>/bluez-5.54/**",
    "/usr/include/glib-2.0"
    ],
}

这让我更加不解。我已经花了几个小时在这上面,我不知道为什么这些包含不起作用。

标签: clinuxgccmakefilebluez

解决方案


推荐阅读