【问题标题】:implicit declaration of pivot root causing a compiler error枢轴根的隐式声明导致编译器错误
【发布时间】:2021-01-16 21:25:52
【问题描述】:

我在尝试创建自制容器时遇到这些编译器错误

warning: implicit declaration of function ‘sys_pivot_root’; did you mean ‘SYS_pivot_root’? [-Wimplicit-function-declaration]
TRY (sys_pivot_root(wd, "/dir/oldroot"));

然后我将 sys_pivot_root 更改为 SYS_pivot_root 然后出现以下错误消息。

install_rootg.c:61:9: error: called object is not a function or function pointer
TRY (SYS_pivot_root(wd, "/dir/oldroot"));

然后我查看 syscall.h 以查看该函数是否存在。我得到以下行

asmlinkage long sys_pivot_root  (const char __user *    new_root, const char __user *   put_old)    

为什么会出现这些编译器错误?我已经有一个星期没能解决这个问题了。

我按照这个确切的顺序包含头文件。

#define _GNU_SOURCE
#include <errno.h>
#include <stdio.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <limits.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/mman.h>

任何帮助将不胜感激。提前谢谢!

【问题讨论】:

  • 根据谷歌快速搜索,函数的名称是pivot_rootSYS_pivot_root 是一个定义的常量,将作为第一个参数传递给syscall
  • 感谢您的回复。 pivot_root 也出现了同样的问题。

标签: c linux containers system-calls mount


【解决方案1】:

我想通了,所以没有这样的函数已经定义为 pivot_root。 你可以调用 syscall(SYS_pivot_root, ... 并调用 pivot_root。 查看手册页的用法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 2016-05-13
    • 2019-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    相关资源
    最近更新 更多