0

[Edit: The question is flawed, the file I described as "main.c" was actually "main.cpp" and that it why I was having an issue, calling a C function from a C++ file. The question is thus incorrect and doesn't have an answer, but if you have this undefined symbol issue, also think about checking you're not mixing C & C++.]

I'm using uVision 5 to develop a firmware, however I can't get the linker to find one of my functions.

main.c :

#include "Test.h"

int main()
{
  return three();
}

Test.h :

#ifndef TEST_H
#define TEST_H

int three();

#endif

Test.c

#include "Test.h"

int three()
{
    return 3;
}

All those files are at the root of my project, I know they get compiled as if I introduce a syntax error in them, compiler reports an error. Also looking at the map file produced, I see that three() was removed:

Removing test.o(i.three), (4 bytes).

For testing purposes, I had --no_remove to linker command line, map file now contains:

0x0002ba76   0x00000004   Code   RO            1    i.three             test.o

So obviously, the linker is well aware of my function, and will or won't remove it depending on flags.

Regardless, it reports:

.\build\uvision5\test.axf: Error: L6218E: Undefined symbol three() (referred from main.o).
Not enough information to list image symbols.
user1532080
  • 243
  • 2
  • 11
  • I have just tried your code, and it builds well for me with a generic ARM Cortex M0. Are you sure that `test.c` is added to your project and get compiled? – Guillaume Michel Feb 02 '17 at 13:41
  • Thanks Guillaume. The mistake was somewhere else, my question is incorrect, main.c was actually main.cpp, so the function had to be declared extern "C"... Apologies and thanks for your help! – user1532080 Feb 02 '17 at 16:16
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – n. m. could be an AI Feb 02 '17 at 16:36

1 Answers1

1

Flawed question, it was actually a case of mixing C/C++, in which case you'll get a symbol missing if you call a C function from C++ without declaring it extern C.

user1532080
  • 243
  • 2
  • 11