c - Linux驱动模块编译问题

标签 c linux linux-kernel embedded linux-device-driver

我从http://examples.oreilly.com/9780596005900/ 下载了一些非常著名的linux 内核示例模块。

并尝试在我的系统上编译。

我的系统信息:

cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"

uname -a
Linux user 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:51:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

cd 示例/简单 制作

出错

make -C /lib/modules/3.13.0-32-generic/build M=/home/user/projects/self/examples/simple LDDINCDIR=/home/user/projects/self/examples/simple/../include modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-32-generic'
/usr/src/linux-headers-3.13.0-32-generic/arch/x86/Makefile:98: stack protector enabled but no compiler support
/usr/src/linux-headers-3.13.0-32-generic/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/user/projects/self/examples/simple/Makefile". Fix it to use ccflags-y.  Stop.
make[1]: *** [_module_/home/user/projects/self/examples/simple] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-32-generic'
make: *** [default] Error 2

我开始知道现在内核构建系统不允许在内核之外更改 CFLAGS,所以以这种方式更改 Makefile

-CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR)
+ccflags-y  += $(DEBFLAGS) -I$(LDDINCDIR)

现在再次生成并获取以下错误消息

make -C /lib/modules/3.13.0-32-generic/build M=/home/user/projects/self/examples/simple LDDINCDIR=/home/user/projects/self/examples/simple/../include modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-32-generic'
/usr/src/linux-headers-3.13.0-32-generic/arch/x86/Makefile:98: stack protector enabled but no compiler support
/usr/src/linux-headers-3.13.0-32-generic/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
  CC [M]  /home/user/projects/self/examples/simple/simple.o
cc1: error: unrecognized command line option "-m64"
cc1: error: unrecognized command line option "-mno-mmx"
cc1: error: unrecognized command line option "-mno-sse"
cc1: error: unrecognized command line option "-mno-red-zone"
cc1: error: unrecognized command line option "-mcmodel=kernel"
cc1: error: unrecognized command line option "-maccumulate-outgoing-args"
make[2]: *** [/home/user/projects/self/examples/simple/simple.o] Error 1
make[1]: *** [_module_/home/user/projects/self/examples/simple] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-32-generic'
make: *** [default] Error 2

早些时候我已经在我的 32 位系统上成功地编译了这些示例,但现在我转移到 64 位系统并遇到了这个错误。我已经用谷歌搜索了这些错误,但直到现在都没有任何帮助。

让我如何解决这个编译错误。

最佳答案

如果您的编译目录或包含内核源代码的目录中有空格,请尝试删除它们并再次make

如果您的编译目录中没有空格并且您仍然收到此错误,则您的内核编译可能会失败,因为它的目录属于 root 并且您正在以非特权用户身份运行用户。试试 sudo make

关于c - Linux驱动模块编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36906508/

相关文章:

c - 初始化为空字符串的字符数组元素的值

c - 为什么输入(换行)不会退出scanf?

c - 为什么\b 不被 ex 识别。 K&R 1-10?

linux-kernel - 从 x86 内核获取 TSC 速率

c - #define func(x, y) x + y/x

c++ - 在 Qt Gui 中使用 std::cout

linux - 创建可移植和静态的 fortran linux 二进制文件?

linux - 在 bash 中使用列

linux - 连接被peer重置,linux内核保持空闲连接多久

linux - KVM 可以在没有 libvirt 的情况下工作吗?