交叉编译内核模块
我正在尝试在我的 intel x86 主机上交叉编译 ARM 架构的 helloworld 内核 (2.6.x) 模块。
ARM 的 codesourcery 工具链位于:/home/ravi/workspace/hawk/arm-2009q3
内核源代码位于:/home/ravi/workspace/hawk/linux- omapl1
我的 Makefile:
ARCH=arm
CROSS_COMPILE=arm-none-linux-gnueabi
obj-m := Hello.o
KDIR := /home/ravi/workspace/hawk/linux-omapl1
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
当我运行 make 时,生成的 .ko 是我的主机的,这意味着 makefile 正在调用本机编译器而不是交叉编译器。我做错了什么?交叉编译器的二进制文件在我的路径中。
I'm trying to cross compile a helloworld kernel (2.6.x) module for ARM architecture on my intel x86 host.
The codesourcery tool chain for ARM is located at: /home/ravi/workspace/hawk/arm-2009q3
The kernel source is located at :/home/ravi/workspace/hawk/linux-omapl1
My Makefile:
ARCH=arm
CROSS_COMPILE=arm-none-linux-gnueabi
obj-m := Hello.o
KDIR := /home/ravi/workspace/hawk/linux-omapl1
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
When i run make, the .ko produced is that of my host machine which means the makefile is invoking the native compiler instead of the cross compiler.What am I doing wrong? The cross compiler's binaries are in my path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将
ARCH
和CROSS_COMPILE
放入 Makefile 中不起作用。您需要将它们放在命令行上:Putting
ARCH
andCROSS_COMPILE
in the Makefile doesn't work. You need to put them on the command line:代替
通过
如果您不想每次都给出这些参数命令行,这也将起作用。
Replace
by
this will also work if you do not want to give these parameter command line each time.
旁注:
SUBDIRS=
已被弃用,取而代之的是M=
。Sidenote:
SUBDIRS=
is deprecated in favor ofM=
.你可以尝试一下吗,你忘了将 ARCH 和 CROSS_COMPILE 添加到默认和干净的中
could you try, you forgot to add ARCH and CROSS_COMPILE into the default and clean
在 Makefile 变量声明末尾添加
export
将使它们可用于子 shell。并将破折号添加到CROSS_COMPILE
前缀,如 JayM 指出的,以及M< /code> 而不是 user502515 回答的
SUBDIRS
。在 Makefile 中使用
:=
而不是=
通常是一个好主意,因此变量只被插值一次。但在这种特殊情况下确实并不重要。adding
export
at the end of your Makefile variable declarations will make them available to subshells. and add the dash to theCROSS_COMPILE
prefix as JayM pointed out, andM
instead ofSUBDIRS
as user502515 answered.and it's generally a good idea to use
:=
rather than=
in a Makefile, so the variable only gets interpolated once. really doesn't matter in this particular case though.