I have compile the hello program,but failed. in my directory hello, I have include and src directory. In include directory there is hello.h file. In src directory ,there are hello.c Makefile fils.
my hello.h file is as bellow:
#ifndef HELLO_H
#define HELLO_H
#define A 10
#endif
My hello.c is as bellow:
#include
#include
#include
#include
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk("Hello World!\n");
printk("a=%d\n", A);
return 0;
}
static void hello_exit(void)
{
printk("Good bye!\n");
}
module_init(hello_init);
module_exit(hello_exit);
My Makfile is as bellow:
KDIR:=/lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
obj-m:=hello.o
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(RM) .*.cmd *.o *.ko -r .tmp*
when i was in src directory , i run make ,but have some errons;
[y041138@302wan hello]$ make
make -C /lib/modules/2.6.8.1/build SUBDIRS=/home/y041138/hello modules
make[1]: Entering directory `/usr/src/linux-2.6.8.1'
CC [M] /home/y041138/hello/hello.o
/home/y041138/hello/hello.c:4:19: hello.h: No such file or directory
/home/y041138/hello/hello.c: In function `hello_init':
/home/y041138/hello/hello.c:10: error: `A' undeclared (first use in this functi)
/home/y041138/hello/hello.c:10: error: (Each undeclared identifier is reported e
/home/y041138/hello/hello.c:10: error: for each function it appears in.)
make[2]: *** [/home/y041138/hello/hello.o] Error 1
make[1]: *** [_module_/home/y041138/hello] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.8.1'
make: *** [default] Error 2
[y041138@302wan hello]$
there is hello.h file in include ,why said that there is no hello.h file??
I guess there is something wrong in my Makefile
can you help me ,and write a right Makefile or let me get pass the compiler.
try using #include "hello.
try using
#include "hello.h"
instead of < hello.h >
sorry, i can`t pass the compiler
sorry, last time my hello.h is in the same directory src with hello.c and Makefile, in this situation i can pass. but if hello.h is in include, can`t pass.
why ,can you tell me ,thank you
my include in hello.c is:
#include
#include
#include
#include "hello.h"
When you use this syntax: #i
When you use this syntax:
#include
the compiler will search the system include directories, such as /usr/include, for the header file. When you use this syntax:
#include "hello.h"
the compiler will search for file relative to your present working directory. For example, you could also specify this:
#include "headers/hello.h"
or an absolute pathname as well:
#include "/usr/src/headers/hello.h"
thank you very much. i pass
thank you very much.
i pass if i do as you said
Also, if you want to keep all
Also, if you want to keep all your header files inside a given directory (let's suppose the "fooheaders" subdirectory) and don't want to repeat the "fooheaders/" prefix everywhere, when you compile a file that uses a header in there, use #include "header.h" in it and tell the compiler to try to find headers in that directory too with the -Ifooheaders option.
The compiler doesn't know whe
The compiler doesn't know where hello.h is, because you haven't told it. Use the -I argument to gcc, or set CPATH to include the path to the mising hello.h and try again.