c - 使用 acl.h - 对 `acl_init' 错误的 undefined reference

标签 c linux gcc acl undefined-reference

我想编写简单的 C 程序来为 Linux 上的一个特定文件设置 ACL。我的起始代码试图使用“acl.h”中的函数。我正在使用 Ubuntu 13.10,我已经安装了“访问控制列表实用程序”-“acl 2.2.52-1”。这是我的代码:

#include <sys/acl.h>
#include <stdio.h>

int main () {     
 acl_t aclvar;
 int count = 1;   
 aclvar = acl_init(count);
 return 0;
}

问题是,在使用“gcc myAcl.c”或“gcc -lacl myAcl.c”进行编译时出现错误:

/tmp/cc5sVzSR.o: In function `main':
myAcl.c:(.text+0x15): undefined reference to `acl_init'
collect2: error: ld returned 1 exit status

我该如何解决这个错误?

最佳答案

您链接到的库需要放在最后

gcc  myAcl.c -lacl

关于c - 使用 acl.h - 对 `acl_init' 错误的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19666050/

相关文章:

c - 为二维数组动态分配空间

linux - 是否可以在 sed 中使用匹配的字符串作为 shell date 命令的输入?

linux - 如何在 docker 镜像中安装 python 模块?

linux - 为 linux 编写系统调用

c++ - 使用 Cygwin/GCC 构建 Boost 库时的名称冲突

c++ - 通过安排任务最大化分数

c - "rand()"不工作,每次执行后我都会得到相同的数字

c - undefined reference gcc

c - 如何在 printf 中插入动态输出?

c++ - 使用 GCC 构建 Linux 可执行文件