Im trying to make a simple hello module.
This is the c file:
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Daniel");
MODULE_DESCRIPTION("A Simple Hello World module");
static int __init hello_init(void)
{
printk(KERN_INFO "Hello world!\n");
return 0; // Non-zero return means that the module couldn't be loaded.
}
static void __exit hello_cleanup(void)
{
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(hello_init);
module_exit(hello_cleanup);
This is the makefile:
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
Ive placed them in ~/HelloModule
and when I run the make command there it gives me this error:
make -C /lib/modules/4.13.0-25-generic/build M=/home/dan/HelloModule modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-25-generic'
scripts/Makefile.build:44: /home/dan/HelloModule/Makefile: No such file or directory
make[2]: *** No rule to make target '/home/dan/HelloModule/Makefile'. Stop.
Makefile:1550: recipe for target '_module_/home/dan/HelloModule' failed
make[1]: *** [_module_/home/dan/HelloModule] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-25-generic'
makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
For some reason on the 4th line it seems like the make script is trying to go into the directory /home/dan/HelloModule/Makefile, which isn't a directory. any ideas on why this is happening and how to fix it?
I figured it out. its not trying to access a directory its trying to access the Makefile which is case sensitive so it has to be Makefile not makefile
Related
i am very new in build systems and i am trying to build c++ file with mingw compiler and makefile on windows.
i installed mingw and added it to PATH. My code as follows
//main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World !!!! "
return 0;
}
//Makefile
program:
g++ main.cpp -o program
i change my working directory as C:\MyDir which is included my .cpp and Makefile
cd C:\\MyDir
C:\\MyDir> make
i get the error
make *** no targets specified and no makefile found. stop ...
Do you have any idea about this problem, thanks..
Downloaded 5.0.5 from Redis
cd to src directory
make
Surely this must work for someone else out there. Any idea/ hintg about how to fix this?
Short version:
In net.c ...
make[3]: Entering directory '/cygdrive/c/Users/pmoran/Downloads/redis-5.0.5/deps/hiredis'
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
net.c:270:21: error: storage size of ‘hints’ isn’t known
struct addrinfo hints, *servinfo, *bservinfo, *p, *b;
^~~~~
and later
net.c:337:40: error: dereferencing pointer to incomplete type ‘struct addrinfo’
for (p = servinfo; p != NULL; p = p->ai_next) {
^~
then
make[3]: *** [Makefile:156: net.o] Error 1
make[3]: Leaving directory '/cygdrive/c/Users/pmoran/Downloads/redis-5.0.5/deps/hiredis'
make[2]: *** [Makefile:46: hiredis] Error 2
make[2]: Leaving directory '/cygdrive/c/Users/pmoran/Downloads/redis-5.0.5/deps'
and finally
cc: error: ../deps/hiredis/libhiredis.a: No such file or directory
cc: error: ../deps/lua/src/liblua.a: No such file or directory
make[1]: *** [Makefile:219: redis-server] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/pmoran/Downloads/redis-5.0.5/src'
make: *** [Makefile:6: all] Error 2
I had the same exact problem and I found the best solution was to use an older version of redis. Redis 3.2.13 was updated recently (March 2019) so it has all the functionality I need. If you use it, you do have to add the following to redis-3.2.13/deps/hiredis/net.c after the 'include' statements:
#ifdef __CYGWIN__
#define TCP_KEEPCNT 8
#define TCP_KEEPINTVL 150
#define TCP_KEEPIDLE 14400
#endif
After that I was able to run make from the root directory:
make distclean
make
This is based on this github conversation.
Hope this helps!
You can have a try.
Step 1:
Remove segment '-std=c99' from line
$(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
in file Makefile under .\redis-5.0.5\deps\hiredis
Ste 2:
Add the following segment after includes deps/hiredis/net.c after the 'include' statements:
#ifndef TCP_KEEPCNT
#define TCP_KEEPCNT 8
#endif
#ifndef TCP_KEEPINTVL
#define TCP_KEEPINTVL 150
#endif
#ifndef TCP_KEEPIDLE
#define TCP_KEEPIDLE 14400
#endif
I am trying to learn kernel programming but while trying to compile a simple hello world program i am getting the following error.
make −C /lib/modules/3.2.0-67-generic/build M=/home/arun/KPrograms modules
make[1]: Entering directory /home/arun/KPrograms'
make[1]: *** No rule to make target−C'. Stop.
make[1]: Leaving directory `/home/arun/KPrograms'
make: * [all] Error 2
my Makefile is
obj−m += hello−1.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
You should replace all the −C in Makefile into -C. The dash character is incorrect.
Hi all,
You must type your code on your own. In some cases copy paste does not work. You must enter it like this:
obj-m............<enter>
all:....<enter>
<tab>make -C.............<enter>
clean:..............<enter>
<tab>make -C...........<esc> <:wq>
That will probably solve your problem.
good luck
Hi I am trying to write a 'Hello World' kernel module.
I wrote the following C code:
Module514.c
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("BMC")
MODULE_DESCRIPTION(" My module]")
static int __init module514(void){
printk(KERN_INFO"Hello World");
return 0;
}
static void __exit module514_cleanup(void){
printk(KERN_INFO"unloaded")
}
module_init(module514);
module_exit(module514_cleanup);
Then created the following Makefile
obj-m += Module514.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
But when I give make I get the following message.
make: Nothing to be done for `all'.
What am I doing wrong.
The problem here seems to have been caused by my Vim configuration. When I used TAB to indent the makefile spaces were getting inserted instead of TAB. Once I corrected this using a different editor all is going file.
PS: Also makefile need to be named with capital M = Makefile
I wish to access some registers of my ARM Cortex-A8 board which are by default in a non-accessible state. Ubuntu 9.10 runs on this board. So, to access them I have to in-turn change 1 other register settings (Allow-access-register) first. To change this Allow-access-register, I found out that I must do it only in Kernel mode and not in the user mode.
So, I referred how to program in Kernel mode and I got to this wonderful tutorial. I wrote this small hello world program and a make file. Note that I'm still running this program on my x86 Desktop (Ubutnu 10.04) and not YET on my ARM processor. Not until I get a hang over Kernel level programming.
I get these errors. Whats going wrong here?
Help!
Errors I get on my i.MX515 board
ubuntu#ubuntu-desktop:~/Documents/Kernel_Programming$ make
make -C /lib/modules/2.6.31-203-gee1fdae/build M=/home/ubuntu/Documents/Kernel_Programming modules
make[1]: Entering directory `/usr/src/linux'
make[1]: *** No rule to make target `modules'. Stop.
make[1]: Leaving directory `/usr/src/linux'
make: *** [all] Error 2
Errors I get
ubuntu#ubuntu-desktop:~/Documents$ make
make -C /lib/modules/2.6.32-23-generic/build M=/home/ubuntu/Documents modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-23-generic'
make[2]: *** No rule to make target `/home/ubuntu/Documents/hello-1.c',
needed by `/home/ubuntu/Documents/hello-1.o'. Stop.
make[1]: *** [_module_/home/ubuntu/Documents] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-23-generic'
make: *** [all] Error 2
Program
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "\nHello World! I'm programming in Kernel Mode\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "\nBye Bye blue bird\n");
}
makefile
obj-m +=hello-1.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
I don't know if it's just the formatting of your post or not, but the kernel build scripts are looking for "Makefile" and you have "makefile" (difference in case). Could that really be the problem? Plus, is your username "ubuntu"?
There is a typo in your make command like:
It should be:
make -C /lib/modules/2.6.32-23-generic/build M=/home/ubuntu/Documents modules
not
make -C /lb/modules/2.6.32-23-generic/build M=/home/ubuntu/Documents modules