cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX showing undefined reference to global variable

ET.2
Associate III

I am new to TouchGFX, I ran into a problem that using TouchGFX 4.21.1 on STM32H743Eval 2 , I add a global variable (e.g. counter) within "USER CODE BEGIN 0", , in StartDefaultTask, add counter++ in the main.c file, follow MVP design procedure, just want to dispaly counter value in TextTArea widget, CubeIDE code compiling is ok, but when click "run simulator", it appers "C:\TouchGFXProjects\STM32H743\TouchGFX/gui/src/model/Model.cpp:13: undefined reference to `counter'

I am also using 4.18.0 of touchgfx, both have same symptom, is there any setting I missed, please help, thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi

You can't use with simulator global variables from Your main.c.

If You won't check Your program with global variables in simulator You must use #ifndef SIMULATOR in Model.cpp

#ifndef SIMULATOR
 
extern "C"
{
	#include "main.h"
}
 
#endif

View solution in original post

5 REPLIES 5
SKacp.1
Senior II

Hello,

Please use extern "C" and include Your "h" file with global variables in Model.cpp.

extern "C"
{
	#include "main.h"
}

Thanks for the reply, I add exter C as you suggest as below:

#include <gui/model/Model.hpp>

#include <gui/model/ModelListener.hpp>

extern "C"

{

#include "main.h"

}

extern int counter;

Model::Model() : modelListener(0)

{

}

void Model::tick()

{

modelListener->indxpresenter(counter);

}

but, ​it shows no main.h as following...

Compile

    make -f simulator/gcc/Makefile -j8

    Reading ./application.config

    Compiling gui/src/model/Model.cpp

    gui/src/model/Model.cpp:6:11: fatal error: main.h: No such file or directory

     #include "main.h"

          ^~~~~~~~

    compilation terminated.

Hi

You can't use with simulator global variables from Your main.c.

If You won't check Your program with global variables in simulator You must use #ifndef SIMULATOR in Model.cpp

#ifndef SIMULATOR
 
extern "C"
{
	#include "main.h"
}
 
#endif

ET.2
Associate III

Got it, I was stuck on simulator for a while, it is working by skipping simulator testing. Thanks for your help.

Hi,

Welcome. Please select as best.

Best regards,

Slawek