ST意法半导体
直播中

caosurround

13年用户 953经验值
私信 关注
[问答]

include或extern var的模拟器错误问题如何处理?

  • #include
  • #include "../../Core/Inc/hello.h"                         // NO in simulator TouchGFX, Yes in CUBEIDEMX
  • extern int myvar;                                                        // NO in simulator TouchGFX, Yes in CUBEIDEMX
  • Screen1View::Screen1View()
  • {
  • }
  • void Screen1View::setupScreen()
  • {
  •     Screen1ViewBase::setupScreen();
  • }
  • void Screen1View::tearDownScreen()
  • {
  •     Screen1ViewBase::tearDownScreen();
  • }
  • void Screen1View::simpleFunc()
  • {
  •     ciao();                                                // err in simulator TouchGFX
  •     myvar = 7;                                        // err in simulator TouchGFX
  • }
  • #include "hello.h"
  • int myvar = 0;
  • void ciao(void)
  • {
  • }
  • #ifndef APPLICAtiON_USER_HELLO_H_
  • #define APPLICATION_USER_HELLO_H_
  • #ifdef __cplusplus
  • extern "C" {
  • #endif
  • void ciao(void);
  • #ifdef __cplusplus
  • }
  • #endif
  • #endif /* APPLICATION_USER_HELLO_H_ */
  • #include
  • #include
  • #include "BitmapDatabase.hpp"
  • Screen1ViewBase::Screen1ViewBase() :
  •     buttonCallback(this, &Screen1ViewBase::buttonCallbackHandler)
  • {
  •     box1.setPosition(0, 0, 240, 320);
  •     box1.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
  •     button1.setXY(35, 130);
  •     button1.setBitmaps(touchgfx::Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_ID), touchgfx::Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_PRESSED_ID));
  •     button1.setAction(buttonCallback);
  •     add(box1);
  •     add(button1);
  • }
  • void Screen1ViewBase::setupScreen()
  • {
  • }
  • void Screen1ViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)
  • {
  •     if (&src == &button1)
  •     {
  •         //Interaction1
  •         //When button1 clicked call virtual function
  •         //Call simpleFunc
  •         simpleFunc();
  •     }
  • }
在 CUBEIDEMX works 中编译,在 TOUCHGFX NO 中运行模拟器
错误:
#include "../../Core/Inc/hello.h"
或在
外部内部 myvar;

回帖(1)

王莉

2023-2-8 14:55:31
您不能在模拟器项目中编译与在 CubeIDE 中相同的代码。模拟器 makefile 对“核心”一无所知,因为它在 SDL2 上运行。在您的 gui 代码中包含目标特定代码通常不是最佳实践 - 如果必须,请使用以下代码保护它:


  • #ifndef SIMULATOR
  • /*code*/
  • #endif


如果你的模拟器中确实有你需要的代码,你必须手动编辑 simulator/gcc/Makefile 并更新 source_paths= 和 include_paths=
举报

更多回帖

发帖
×
20
完善资料,
赚取积分