首页 > 解决方案 > 枢轴根的隐式声明导致编译器错误

问题描述

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

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>

任何帮助,将不胜感激。先感谢您!

标签: clinuxcontainerssystem-callsmount

解决方案


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


推荐阅读