Hi,
I have a c program that looks like bellow. In my main.c file, I have included: #include "test.h" main(){ test_init(); }
in my test.h file, I have a declaration static void test_init();
in my test.c file, I have a definition void test_init() { return 1; }
When I do compile, I see: compiling test.c... compiling main.c... linking... .\out\test.axf: Error: L6218E: Undefined symbol test_init(referred from main.o).
I've both declared and defined the function. But still see this error, any thoughts?
Hello Hao,
Function definition does not match what the function does. This can easily confuse the compiler, when it is trying to figure out if a function exists.
void test_init() { return 1; }
should be:
int test_init() { return 1; }
This should resolve the errors.
Do you want the function to be static or not? I think you want to use this function elsewhere, so it should not be declared as static.
See the following forum page, "Using the static keyword in C": community.arm.com/.../using-the-static-keyword-in-c
Then only use:
extern int test_init(void);
in test.h. Then, there should be no warnings.
a static function is, by definition restricted to the module where it is, get rid of the static
Hi actually i was also facing the same issue. In my case what happened is iI kept the driver source files and inlcude files in the other folder thats why linker was not able to link them. Then i cpoied every single file into the project filder and also i gave path of that folder by going into the option folder and then c/c++ and then include path option.
No, that's not what happened. The linker does not care at all where source files are.