编译器说 uuid.h 未找到,但 apt-get 说它是

Compiler says uuid.h not found but apt-get says it is

在编译包含 uuid.h 的 C++ 项目时出现编译错误:

fatal error: uuid.h: No such file or directory

我不确定出了什么问题。可能是我的编译器指令有误,或者我确实没有安装该文件(但我认为这不是问题所在)。

sudo apt-get install uuid-dev

以上命令输出:uuid-dev is already the newest version

我的 makefile 就是这样:

all:
    g++ -o bin/myapplication src/main.cpp -std=c++11

编辑: 在 .h 文件中:

#include <uuid.h>

知道问题出在哪里吗?

我相信较新版本的 uuid header 是 <uuid/uuid.h>

包裹的 file list 表明它包含 /usr/include/uuid/uuid.h。由于您的默认包含路径查找相对于 /usr/include 的文件,您需要编写 <uuid/uuid.h>,或将 -I/usr/include/uuid 添加到您的编译选项。

但是,该软件包还提供了一个 .pc 文件供 pkg-config 使用,该文件旨在抽象出针对库构建程序所需的编译器选项的详细信息。如果你 运行 pkg-config --cflags uuid 你会得到输出 -I/usr/include/uuid,如果你 运行 pkg-config --libs uuid,你会得到输出 -luuid。这些将被合并到您的程序构建中。

因为看起来你正在使用 Make,你应该将这些行添加到你的 Makefile:

CFLAGS += `pkg-config --cflags uuid`
LDFLAGS += `pkg-config --libs uuid`

这会自动将必要的 -I-l 选项合并到您的编译命令中——它也适用于 UUID 库可能安装在不同位置的其他系统。