2023-02-28 10:15 PM
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.
Solved! Go to Solution.
2023-02-28 11:38 PM
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
2023-02-28 10:58 PM
Hello,
Please use extern "C" and include Your "h" file with global variables in Model.cpp.
extern "C"
{
#include "main.h"
}
2023-02-28 11:15 PM
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.
2023-02-28 11:38 PM
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
2023-03-01 02:52 PM
Got it, I was stuck on simulator for a while, it is working by skipping simulator testing. Thanks for your help.
2023-03-01 11:29 PM
Hi,
Welcome. Please select as best.
Best regards,
Slawek