【问题标题】:Simple Make File Error简单的制作文件错误
【发布时间】:2016-02-29 00:20:07
【问题描述】:

我正在尝试创建一个简单的 make 文件并使用它来构建一个简单的 c 程序。该环境在使用最新版本的 ubuntu 的虚拟框中。我已经下载了 ubuntu 的 linux 头文件,但仍然出现错误。

你好.c

#include <linux/init.h>
#include <linux/module.h>

static int hello_init(void) {
    printk(KERN_ALERT "TEST: Hello world, this is soliducode\n");
    return 0;
}

static void hello_exit(void) {
    printk(KERN_ALERT "TEST: Good byte, from soliduscode");
}

module_init(hello_init);
module_exit(hello_exit);

生成文件

obj-m += Hello.o

KDIR = /usr/src/linux-headers-4.2.0-16-generic

all: 
    $(MAKE) -C $(KDIR) SUBSIRS=$ modules

clean:
    rm -rf *.o *.ko *.mod.* *.symvers *.order

错误

make -C /usr/src/linux-headers-4.2.0-16-generic SUBSIRS=modules
make[1]: Entering directory '/usr/src/linux-headers-4.2.0-16-generic'
arch/x86/Makefile:138: CONFIG_X86_X32 enabled but no binutils support
Makefile:669: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
  HOSTCC  scripts/basic/fixdep
scripts/basic/fixdep.c:462:1: fatal error: opening dependency file scripts/basic/.fixdep.d: Permission denied
 }
 ^
compilation terminated.
scripts/Makefile.host:91: recipe for target 'scripts/basic/fixdep' failed
make[3]: *** [scripts/basic/fixdep] Error 1
Makefile:449: recipe for target 'scripts_basic' failed
make[2]: *** [scripts_basic] Error 2
make[2]: *** No rule to make target 'arch/x86/entry/syscalls/syscall_32.tbl', needed by 'arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h'.  Stop.
arch/x86/Makefile:184: recipe for target 'archheaders' failed
make[1]: *** [archheaders] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.2.0-16-generic'
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 2

【问题讨论】:

    标签: c ubuntu makefile virtualbox


    【解决方案1】:

    您的内核配置似乎无效。

    有关于如何在 Ubuntu 上构建自己的内核的文档,例如 https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel

    【讨论】:

      【解决方案2】:

      尝试在 Makefile 中使用 M=${PWD} 选项。

      命令:

      make -C /lib/modules/`uname -r`/build M=${PWD} modules
      

      【讨论】:

        【解决方案3】:

        @Manish Dharanenthiran 为我解决了这个问题。 我在这个问题上待了大约 2 天。 编译了一个新内核,从https://www.kali.org/downloads/ 下载另一个内核,仍然出现这些错误。

        为了帮助解决这类问题,我建议使用以下路径 -

        1. 首先检查你运行的内核

          uname -r

        2. 检查您是否在/usr/src 中获得了当前的内核 linux-headers

          ls -a /usr/src

        • 如果不安装,则需要安装它们但 apt-get 不提供旧版本的 linux-headers 检查您的是否在收到的列表中可用

          apt-cache search linux-headers

        • 如果您的当前版本在那里,请跳转到 3。

        • 如果您当前的版本不可用,您需要:apt-get update & apt-get upgrade / 安装新机器 / 编译新内核

        注意 - 根据我的经验(我都做过),更新和升级是最快的。

        apt-get update
        apt-get upgrade
        reboot
        

        启动时在 grub 菜单中选择新内核

        如果您在启动时看不到/捕捉菜单,可以使用更大的 GRUB_TIMEOUT 值编辑this file


        1. 下载需要的 linux-headers

          apt-get install linux-headers-$(uname -r)

        2. 如果问题仍未解决,请尝试在您的 Makefile 中使用 M=${PWD},而不是 @Manish Dharanenthiran 中提到的 M=$(PWD)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-05-27
          • 1970-01-01
          • 2017-04-16
          • 2012-07-08
          • 1970-01-01
          • 1970-01-01
          • 2013-03-12
          相关资源
          最近更新 更多