您的位置:首页 > 运维架构 > Linux

Linux学习记录

2012-01-19 09:06 232 查看
初学Linux,Hello World都弄了很久,此处记录一下。

首先要注意的是,目录名不要带空格,否则需要加上转义符,这导致了此前的make不成功。

shell的出错提示如下:

[enjolras@TMServer Test Test]$ make

make -C /lib/modules/2.6.9-42.ELsmp/build M=/home/enjolras/Test Test modules

make[1]: Entering directory `/usr/src/kernels/2.6.9-42.EL-smp-i686'

make[1]: *** No rule to make target `Test'. Stop.

make[1]: Leaving directory `/usr/src/kernels/2.6.9-42.EL-smp-i686'

make: *** [default] Error 2

[enjolras@TMServer Test Test]$ pwd

/home/enjolras/Test Test

空格没带转义符,导致Makefile中用pwd获取的当前路径不对。

以下为Hello World 的Makefile。

# obj-m is a list of what kernel modules to build. The .o and other

# objects will be automatically built from the corresponding .c file -

# no need to list the source files explicitly.

# 此处指定编译的模块 自动寻找hello_printk.c

# :=代表立刻赋值。用=的话,会有一个展开的过程,一般情况下用:=。

obj-m := hello_printk.o

# KDIR is the location of the kernel source. The current standard is

# to link to the associated source tree from the directory containing

# the compiled modules.

#此处指定内核源码路径 shell 指定当前使用的shell uname -r 指定内核核心版本

KDIR := /lib/modules/$(shell uname -r)/build

# PWD is the current working directory and the location of our module

# source files.

#pwd 获取当前路径

PWD := $(shell pwd)

# default is the default make target. The rule here says to run make

# with a working directory of the directory containing the kernel

# source and compile only the modules in the PWD (local) directory.

# 默认情况下 即输入make不带参数情况下,此make规则将当前工作目录与内核源码一起编译,

#仅仅编译当前目录模块的代码

default:

(TAB)$(MAKE) -C $(KDIR) M=$(PWD) modules
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: