First of all, I'm not sure if the title describes well the problem, feel free to change or suggest a more fitting heading.
I have the following problem: I need to pass a function pointer to some struct. When I define the function in the same file, this works perfectly fine. See here:
static void a_func(int param1, /*...*/) {
//...
}
static const struct bt_mesh_handlers my_handlers = {
.set = a_func,
// ...
};
When I now define this function in another file, I can't get it to work: the header file (include guards are not shown here):
//function declaration:
void a_func(int param1, /*...*/);
the c file:
//function definition (this was defined wrongly as static before)
void a_func(int param1, /*...*/) {
//...
}
in the main-file:
#include "myheader.h"
static const struct bt_mesh_handlers my_handlers = {
.set = a_func,
// ...
};
When I outsource my function to another file, I get the following error during build:
undefined reference to `a_func'
I already did some research and I'm relatively sure that in the file where a_func is defined, there automatically is generated a function pointer with the same name. Consequently, I can use that pointer to hand over my function to the struct.
But I don't know how to get that function pointer from the outsourced file into my main file. What would a good solution look like?