Results 1 to 4 of 4
Hi all,
I have an object file foo.o which provide a function foo().
when I use this object file with simple main.c as shown below it works correctly.
Code:
#main.c
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-11-2012 #1Just Joined!
- Join Date
- Apr 2012
- Posts
- 7
Adding a new object file to kernel source code and use it's function
Hi all,
I have an object file foo.o which provide a function foo().
when I use this object file with simple main.c as shown below it works correctly.
I use gcc for compile & link.Code:#main.c include "foo.h" int main() { foo(); return 0; }
Goal:Code:gcc -o foo foo.o main.c
I want to use foo() in init/main.c of my linux-2.6.35 kernel source code.
What I've done:
I added foo.o and foo.h to the kernel/init/ directory, modified my init/main.c to use foo(), and added foo.o to obj-y in init/Makefile as shown below.
Problem:Code:obj-y := main.o version.o mounts.o foo.o
I get these errors when I make the kernel..
I know the problem arises from Makefile, but I don't know how to solve it.Code:init/built-in.o: In function `foo1': foo.c:(.text+0xe3): undefined reference to `printf' foo.c:(.text+0xf8): undefined reference to `printf' foo.c:(.text+0x19f): undefined reference to `printf' foo.c:(.text+0x1b8): undefined reference to `printf' init/built-in.o: In function `foo2': foo.c:(.text+0x1e6): undefined reference to `printf' init/built-in.o:foo.c:(.text+0x1ff): more undefined references to `printf' follow init/built-in.o: In function `foo3': foo.c:(.text+0xcb0): undefined reference to `putchar' foo.c:(.text+0xe29): undefined reference to `stdout' foo.c:(.text+0xe3c): undefined reference to `fputc' foo.c:(.text+0xe51): undefined reference to `stdout' foo.c:(.text+0xe63): undefined reference to `fputc' foo.c:(.text+0xe76): undefined reference to `puts' . . .
I would appreciate any help!
Thanks!
- 10-15-2012 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,227
You have some studying to do. Writing kernel code is NOT the same as normal user code, which is what you have written. There are documents and books online that will help, but you have a steep learning curve to overcome before you can do this effectively. Note that the standard library functions as printf, fputc, and such DO NOT WORK with kernel code!
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-15-2012 #3Just Joined!
- Join Date
- Apr 2012
- Posts
- 7
Thank you Rubberman for your answer.
How can I convert some code to work with kernel code?? can you offer me some documents or books to do this?
- 10-15-2012 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,227
Available in ebook form, and in many cases for free online:
Linux Kernel Development, Author: Robert Love, Publisher: Addison-Wesley
Linux Device Drivers, Author: Jonathan Corbet, Publisher: O'Reilly
Google searches should find them PDQ.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
