cancel
Showing results for 
Search instead for 
Did you mean: 

REPOST: undefined reference to... mixing C and C++ code

Question - TouchGFX Community repost - Teo Lucco - September 19 2018

Hi everybody,

in order to simulate hardware interactions, I'm trying to add a console interpreter I already developed.

This console in write in C, so I have console.h and console.c files.

What I've done, following this article, was to add an extern reference in frontendApplication.hpp:

frontendApplication.hpp
...
extern "C" {
 void MiniConsole(uint8_t c);
 //#include<gui/common/console.h>
}
class FrontendApplication : public FrontendApplicationBase
{
public:
 FrontendApplication(Model& m, FrontendHeap& heap);
 virtual ~FrontendApplication() { }
 
 virtual void handleKeyEvent(uint8_t key){
      MiniConsole(key);
 }
...

As can be seen in prevoius code(commented), console.h and console.c are located in gui/common folder.

In console.h, I've the prototype of function MiniConsole:

console.h
...
void MiniConsole(uint8_t c);
...

and in console.c the implementation.

console.c
 
...
 
#include "gui/common/console.h"
 
...
 
void MiniConsole(uint8_t c)
{
 
....
 
}

This works fine if I compile with Visual Studio, but compiling with gcc I obtain the following error:

Converting images
Compiling gui/src/common/console.c
Linking build/bin/simulator.exe
build/MINGW32_NT-6.2/gui/src/common/FrontendApplication.o: In function `ZN19FrontendApplication14handleKeyEventEh':
C:\TouchGFXProjects\AnimatedMenu2/gui/include/gui/common/FrontendApplication.hpp:26: undefined reference to `MiniConsole'
collect2.exe: error: ld returned 1 exit status
simulator/gcc/Makefile:177: recipe for target 'build/bin/simulator.exe' failed
make[2]: *** [build/bin/simulator.exe] Error 1
simulator/gcc/Makefile:173: recipe for target 'generate_assets' failed
make[1]: *** [generate_assets] Error 2
simulator/gcc/Makefile:31: recipe for target 'all' failed
make: *** [all] Error 2

...can somewone help me?

thanks in advance!

Answer - TouchGFX Community repost - Flemming Gram Christensen - September 19 2018

Hello Teo.

Ok. Please check if your gcc is compiling your .c file as c++ (try removing the extern "C").

Also verify that console.o is included in the linker command (e.g. insert echo as first word in the linking line)

sometimes last way is to use the "nm" command to list the symbols in the .o files. Something like:

nm build/MINGW32_NT-6.2/gui/src/common/FrontendApplication.o | c++filt

Note, there is not anything mysterious about calling C functions from the C++ code. All the BSP functions (from ST e.g.) are all C functions.

Regards

0 REPLIES 0