How to setup inter-module function calls

I have developed two modules (A & B) where B depends on A. Module B needs to call function func1 provided by module A.

I successfully kldload module A first, but I cannot load module B due to a linker error:

Code:
kernel: link_elf: symbol func1 undefined

How do I mark func1 for export in module A so the linker can resolve it for module B?

In Linux I would simply add EXPORT_SYMBOL(func1) in module A.

Thank you,
 
I have the following setup:

1. Module A:
File A.h that defines func1 and func2 as follows:

Code:
int func1(int flag);
extern int func2(int flag); /* try extern as well. */
File A.c declares func1 and func2 as follows:

Code:
int func1(int flag) {return flag;}
int func2(int flag) {return flag;}

2. Module B:
File B.c includes A.h and tries to call func1 and func2.


I first kldload A.ko and upon success I try to load B.ko but this fails because func1 and func2 are undefined.
 
The problem is solved.

I added to module B MODULE_DEPEND(A) and func1 and func2 are resolved and I can load module B after loading module A.
 
What chodong says is right in order to achive EXPORT_SYMBOL effect on FreeBSD you need to use MODULE_DEPEND(9), but you also need to keep in mind that:
-the prototype of your functions need to be declared nonstatic otherwise compiler will try to link against them right after compile time.
 
Back
Top