c - 包含路径不适用于 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"
],
}
这让我更加不解。我已经花了几个小时在这上面,我不知道为什么这些包含不起作用。
解决方案
推荐阅读
- sql - SQL - 如何在特定列中选择具有最大值的数据行?[第2部分]
- python - 将 SSH 与应用程序服务器一起使用时 libcrypto.so 中的段错误
- java - 需要使用java读取对象内部的json数组
- amazon-web-services - 将文件直接从 S3 移动到 FTP
- googletest - “SetUpTestCase”或“TearDownTestCase”的拼写错误问题
- django - 序列化器字段可能命名不正确,并且与 GenericRelatedObjectManager 实例上的任何属性或键都不匹配
- ionic-framework - Ionic3 Fileopener 插件对象(…)不是函数错误
- image-processing - 将 Cifar10 数据集转换为 Amazon SageMaker 的 RecordIO 格式
- game-maker - GML 向点移动使对象向右移动
- deep-learning - CNN 的预处理图像?