Results 1 to 3 of 3
Hi,
I am writing a Linux Device driver for 2.6 kernel (for the first time). There is plenty of code so I decided to split it into 2 files. I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-08-2010 #1Just Joined!
- Join Date
- Jan 2010
- Posts
- 10
Global variables in multi-file device driver
Hi,
I am writing a Linux Device driver for 2.6 kernel (for the first time). There is plenty of code so I decided to split it into 2 files. I have 2 global variables that I want both files to use. I could use function parameters but that would be way too cumbersome unfortunately. I can't get this to work though.
----------
----------Code:first.c #include <linux/module.h> .... .... char *mem_ptr; static int __init my_init() { .... }
I get a build (link) time warning as follows:Code:second.c #include <linux/module.h> .... .... extern char *mem_ptr; function compute() { mem_ptr = NULL; .... }
Any ideas why doesn't the extern pick up the global variable from the other file? Do I have my makefile incorrectly defined. It is:Code:Building modules, stage 2. MODPOST *** Warning: "mem_ptr" [/home/guraaf/first.ko] undefined!
Code:obj-m := first.o first-objs := first.o second.o module: $(MAKE) -C $(KERNELDIR) ARCH=ppc M=$(PWD) modules
- 02-09-2010 #2Just Joined!
- Join Date
- Jul 2009
- Posts
- 10
in second.c file
char variable;
EXPORT_SYMBOL(variable);
and use it in first.c file..the above will export the variable to global symbol table so that u can use it anywhere in any module.. remove the extern and try once..
- 02-09-2010 #3Just Joined!
- Join Date
- Jan 2010
- Posts
- 10
Hi,
Thanks for replying. The problem was that the .tmp_versions got into a bad state. As soon as I deleted that direcory everything started working.


Reply With Quote
