cancel
Showing results for 
Search instead for 
Did you mean: 

Simulator error with include or extern var

Damiano
Associate II
#include <gui/screen1_screen/Screen1View.hpp>
 
#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 <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <touchgfx/Color.hpp>
#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();
    }
}

Compile in CUBEIDEMX works, run simulator in TOUCHGFX NO

Error in:

#include "../../Core/Inc/hello.h"

or in

extern int myvar;

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Damiano​,

You cannot compile the same code in a simulator project as in CubeIDE. The simulator makefile does not know anything about "Core" because it runs on SDL2. It is usually not best practice to have target specific code in your gui code - If you must, guard it with :

#ifndef SIMULATOR 
/*code*/ 
#endif
 

If you do have code that you need in your simulator you have to manually edit the simulator/gcc/Makefile and update source_paths= and include_paths=

/Martin

View solution in original post

3 REPLIES 3
Alexandre RENOUX
Principal

Hello,

I do not understand why you have an error because I tried to do the same thing and it worked.

Note: Writing C code in a C++ GUI is not the best way in my opinion. Regarding your goal, you can easily do the same using C++ coding.

I created hello.c in gui\src\common\hello.c and hello.h in gui\include\gui\common\hello.h

Here is the code:

#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 <gui/common/hello.h>
 
int myvar = 0;
 
void ciao(void)
{
}
#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP
 
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
 
class Screen1View : public Screen1ViewBase
{
public:
    Screen1View();
    virtual ~Screen1View() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
 
    virtual void simpleFunc();
protected:
};
 
#endif // SCREEN1VIEW_HPP
#include <gui/screen1_screen/Screen1View.hpp>
 
#include <gui/common/hello.h>
extern int myvar;
 
Screen1View::Screen1View()
{
 
}
 
void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
}
 
void Screen1View::tearDownScreen()
{
    Screen1ViewBase::tearDownScreen();
}
 
void Screen1View::simpleFunc()
{
    ciao();
    myvar = 7;	
}

Hi, thanks for the answer,

my goal is to interface with hardware in TouchGFX applications,

in particular to connect a slider to change the duty cycle of a pwm signal.

The error was here in "run simulator":

 gui/src/screen1_screen/Screen1View.cpp:4:10: fatal error: ../../Core/Inc/hello.h: No such file or directory

     #include "../../Core/Inc/hello.h"

         ^~~~~~~~~~~~~~~~~~~~~~~~

    compilation terminated.

Thanks, with in gui\src\common\hello.c and hello.h in gui\include\gui\common\hello.h

"run simulator" it works.

Hi @Damiano​,

You cannot compile the same code in a simulator project as in CubeIDE. The simulator makefile does not know anything about "Core" because it runs on SDL2. It is usually not best practice to have target specific code in your gui code - If you must, guard it with :

#ifndef SIMULATOR 
/*code*/ 
#endif
 

If you do have code that you need in your simulator you have to manually edit the simulator/gcc/Makefile and update source_paths= and include_paths=

/Martin