[SOLVED]Make error

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read how to get help
Post Reply
hhbuur
Level 1
Level 1
Posts: 10
Joined: Thu Feb 15, 2018 1:17 pm

[SOLVED]Make error

Post by hhbuur » Sun Jul 15, 2018 3:00 am

Can I get some help with understand these error messages. I am trying to make a hello world.
#include<linux/init.h>
#include<linux/module.h>

MODUL_LICENSE("GPL");

static int hello_init(void)
{
printk(KERN_ALERT "Hello world");
retur 0;
}

static void hello_exit(void)
{
printk(KERN_Alert "Goodby");
}

module_init(hello_init);
module_exit(hello_exit);



obj-m +=hello.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean







hhb # make
make -C /lib/modules/4.13.0-39-generic/build M=/home/hans/hhb modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-39-generic'
CC [M] /home/hans/hhb/hello.o
/home/hans/hhb/hello.c:4:15: error: expected declaration specifiers or ‘...’ before string constant
MODUL_LICENSE("GPL");
^
/home/hans/hhb/hello.c: In function ‘hello_init’:
/home/hans/hhb/hello.c:9:1: error: ‘retur’ undeclared (first use in this function)
retur 0;
^
/home/hans/hhb/hello.c:9:1: note: each undeclared identifier is reported only once for each function it appears in
/home/hans/hhb/hello.c:9:7: error: expected ‘;’ before numeric constant
retur 0;
^
/home/hans/hhb/hello.c:10:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
/home/hans/hhb/hello.c: In function ‘hello_exit’:
/home/hans/hhb/hello.c:14:8: error: ‘KERN_Alert’ undeclared (first use in this function)
printk(KERN_Alert "Goodby");
^
/home/hans/hhb/hello.c:14:19: error: expected ‘)’ before string constant
printk(KERN_Alert "Goodby");
^
scripts/Makefile.build:323: recipe for target '/home/hans/hhb/hello.o' failed
make[2]: *** [/home/hans/hhb/hello.o] Error 1
Makefile:1550: recipe for target '_module_/home/hans/hhb' failed
make[1]: *** [_module_/home/hans/hhb] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-39-generic'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
Last edited by hhbuur on Thu Aug 23, 2018 8:45 am, edited 1 time in total.

rene
Level 8
Level 8
Posts: 2182
Joined: Sun Mar 27, 2016 6:58 pm

Re: Make error

Post by rene » Sat Jul 28, 2018 4:49 pm

You have 3 obvious typo's, all of which are pointed out by the error messages. Modulo module signing, the only thing that's otherwise wrong is that you should end your printk strings with "\n" so as to flush them to the kernel message buffer.

hhbuur
Level 1
Level 1
Posts: 10
Joined: Thu Feb 15, 2018 1:17 pm

Re: Make error

Post by hhbuur » Sat Aug 11, 2018 1:12 pm

thanks fore your reply, that help.
can you help me white the next step, i am getting a messed when compelling and the compelling only make two file, "Module.symvers and modules.order" and both are empty.

Code: Select all

 MJ # make
make -C /lib/modules/4.13.0-39-generic/build M=/home/MJ modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-39-generic'
  CC [M]  /home/MJ/hello.o
/home/MJ/hello.c:1:2: error: invalid preprocessing directive #inClude
 #inClude<linux/init.h>
  ^
/home/MJ/hello.c:2:2: error: invalid preprocessing directive #inClude
 #inClude<linux/module.h>
  ^
/home/MJ/hello.c:4:16: error: expected declaration specifiers or ‘...’ before string constant
 MODULE_LICENSE("GPL");
                ^
/home/MJ/hello.c:6:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
 statiC int hello_init(void)
        ^
/home/MJ/hello.c:12:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
 statiC void hello_exit(void)
        ^
/home/MJ/hello.c:17:1: warning: data definition has no type or storage class
 module_init(hello_init);
 ^
/home/MJ/hello.c:17:1: error: type defaults to ‘int’ in declaration of ‘module_init’ [-Werror=implicit-int]
/home/MJ/hello.c:17:1: warning: parameter names (without types) in function declaration
/home/MJ/hello.c:18:1: warning: data definition has no type or storage class
 module_exit(hello_exit);
 ^
/home/MJ/hello.c:18:1: error: type defaults to ‘int’ in declaration of ‘module_exit’ [-Werror=implicit-int]
/home/MJ/hello.c:18:1: warning: parameter names (without types) in function declaration
cc1: some warnings being treated as errors
scripts/Makefile.build:323: recipe for target '/home/MJ/hello.o' failed
make[2]: *** [/home/MJ/hello.o] Error 1
Makefile:1550: recipe for target '_module_/home/MJ' failed
make[1]: *** [_module_/home/MJ] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-39-generic'
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 2
hans MJ # vi Makefile

the Makefile

Code: Select all

obj-m +=hello.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:

	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean  

rene
Level 8
Level 8
Posts: 2182
Joined: Sun Mar 27, 2016 6:58 pm

Re: Make error

Post by rene » Sat Aug 11, 2018 1:47 pm

You now have one obvious typo, again as pointed out by the error message: there's no directive called "inClude". Let me just post the corrected hello.c.

Code: Select all

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

MODULE_LICENSE("GPL");

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

static void __exit hello_exit(void)
{
    printk(KERN_ALERT "Goodbye\n");
}

module_init(hello_init);
module_exit(hello_exit);
Note that I added __init and __exit to to hello_init resp. hello_exit. Do not matter here but should be present generally: when the module's built-in to the kernel __init causes a function to be placed in an after initialization discardable section of the kernel and __exit code is discarded outright.

Code: Select all

rene@hp8k ~/hello $ make
make -C /lib/modules/4.15.0-30-generic/build M=/home/rene/hello modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-30-generic'
Makefile:976: "Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel"
  CC [M]  /home/rene/hello/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/rene/hello/hello.mod.o
  LD [M]  /home/rene/hello/hello.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-30-generic'
rene@hp8k ~/hello $ sudo insmod ./hello.ko && sudo rmmod hello
[sudo] password for rene: 
rene@hp8k ~/hello $ dmesg -t | tail -2
Hello world
Goodbye
Before those two lines dmesg will you telll that insmoding an unsigned module will taint your kernel. Module signing will undoubtedly, hopefully, be explained in the next section of whichever source you are consulting; if not, for now just ignore it.

[EDIT] For some odd reason, the module_init() and module_exit() got stripped from above paste of hello.c; added back again.

hhbuur
Level 1
Level 1
Posts: 10
Joined: Thu Feb 15, 2018 1:17 pm

Re: Make error

Post by hhbuur » Sat Aug 18, 2018 8:04 am

I have come a little further but there is something I do not understand, in the manual there are printet three lines as a result while I only get one, or say otherwise it seems I do not get anything Array

the code

Code: Select all

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

MODULE_LICENSE("GPL");

int paramArray[3];
    module_param_array(paramArray, int,NULL, S_IWUSR | S_IRUSR); 

static int __init array_init(void)
{
    printk("Into the parameter Array demo\n");

    printk("Array elements are :%d\t%d\t%d",paramArray[0],paramArray[1],paramArray[2]);
return 0;
}

static void array_exit(void)
{
    printk(KERN_ALERT "Exiting the array parameter demo\n");
}

module_init(array_init);
module_exit(array_exit);

make

Code: Select all

 make
make -C /lib/modules/4.13.0-39-generic/build M=/home/MJ modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-39-generic'
  CC [M]  /home/MJ/parameterArray.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/MJ/parameterArray.mod.o
  LD [M]  /home/MJ/parameterArray.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-39-generic'
the result

Code: Select all

sudo insmod parameterArray.ko paramArray=1,2,3
 /home/MJ $ dmesg | tail -5
[   58.076836] thinkpad_acpi: EC reports that Thermal Table has changed
[  952.370581] INTO the parameter Array demo
[  952.370583] Array elements are :1	2	3
[ 1555.760650] Exiting the array parameter demo
[ 1702.026904] INTO the parameter Array demo

rene
Level 8
Level 8
Posts: 2182
Joined: Sun Mar 27, 2016 6:58 pm

Re: Make error

Post by rene » Sat Aug 18, 2018 8:34 am

hhbuur wrote:
Sat Aug 18, 2018 8:04 am
[ ... ] in the manual there are printet three lines as a result while I only get one
This is again the issue of you not flushing messages to the kernel message buffer; of you not ending the "Array elements are" printk() with a newline.

Two other remarks: while printk() has a default log level (KERN_WARNING normally) not explicitly specifying one as you do in but one instance is frowned upon. Also, if you mark your module_init() function __init consistency kindly requests you mark your module_exit() function __exit...

One additional remark... you may have in the form of this forum picked one of the worst possible places to go learn Linux kernel programming. It seems the kernelnewbies project is still alive: https://forum.kernelnewbies.org/ and/or https://kernelnewbies.org/ML. That would no doubt be a far better choice.

hhbuur
Level 1
Level 1
Posts: 10
Joined: Thu Feb 15, 2018 1:17 pm

Re: Make error

Post by hhbuur » Thu Aug 23, 2018 8:42 am

ok i consider the problem sloved

Post Reply

Return to “Other topics”