1

I cross-compiled a new Kernel(3.18.10) on Debian Jessie amd64 for RPi2. Later, when I compile a simple Hello-World module with this kernel, however, an error is raised:

make -C /lib/modules/3.18.10-d0u9/build M=/home/pi/Hello-World modules
make[1]: Entering directory '/usr/src/linux-source-3.18'
  CC [M]  /home/pi/Hello-World/main.o
./scripts/recordmcount: 1: ./scripts/recordmcount: Syntax error: "(" unexpected
scripts/Makefile.build:257: recipe for target '/home/pi/Hello-World/main.o' failed
make[2]: *** [/home/pi/Hello-World/main.o] Error 2
Makefile:1398: recipe for target '_module_/home/pi/Hello-World' failed
make[1]: *** [_module_/home/pi/Hello-World] Error 2
make[1]: Leaving directory '/usr/src/linux-source-3.18'
Makefile:19: recipe for target 'modules' failed
make: *** [modules] Error 2

The Hello-World module is fairly simple:

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

static int __init hello_init(void)
{
    printk(KERN_ALERT "Hello, world!\n");
    return 0;
}

static void __exit hello_exit(void)
{
    printk(KERN_ALERT "Bye, World!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Douglas");
MODULE_DESCRIPTION("Hello World program");

And below is the Makefile:

DEBUG = y

ifeq ($(DEBUG),y)
    DEBFLAGS = -O -g -DENABLE_DEBUG
else
    DEBFLAGS = -O2
endif

EXTRA_CFLAGS += $(DEBFLAGS)

ifneq ($(KERNELRELEASE),)
    hello-world-objs := main.o
    obj-m := hello-world.o
else
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)

modules:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

clean:
    rm -fr *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

The directory /lib/modules/XXXX/build and /lib/moduels/XXXX/source have already linked to the source tree via ln -s command.

I have already compiled kernel over 3 days to solve this problem, however, nothing was obtained.

Please help me...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.