2020-01-12 03:04 PM
I am getting compiling errors when trying to include a custom class into a TouchGFX project.
I made a class called "test" with it's test.h and test.cpp components.
//File: test.h
#pragma once
class test
{
public:
test();
~test();
void set_testX(int);
int get_testX();
protected:
int testX;
};
#include "test.cpp"
//File: test.cpp
#include "test.h"
test::test()
{
testX = 0;
}
test::~test()
{
}
void test::set_testX(int x)
{
testX = x;
}
int test::get_testX()
{
return testX;
}
When I include test.h into mainScreenView.cpp (generated from TouchTFX) the code compiles fine.
However, I want test.h to be included into mainScreenView.hpp... When I attempt this, I get multiple definition erorrs, and I have no idea how to fix this....:sad_but_relieved_face:
//File: mainScreenView.cpp
//This code compiles fine when the test.h include is not commented out
#include <gui/mainscreen_screen/mainScreenView.hpp>
#include <gui_generated/mainscreen_screen/mainScreenViewBase.hpp>
#include "BitmapDatabase.hpp"
#include <texts/TextKeysAndLanguages.hpp>
#include <touchgfx/Color.hpp>
//#include <../../simulator/msvs/test.h> //commented out to include in the .hpp
using namespace std;
mainScreenView::mainScreenView()
{
}
void mainScreenView::setupScreen()
{
mainScreenViewBase::setupScreen();
}
void mainScreenView::tearDownScreen()
{
mainScreenViewBase::tearDownScreen();
}
void mainScreenView::set_test_X()
{
int x = testx.get_testX();
//Unicode::UnicodeChar y[10] = new UnicodeChar;
Unicode::snprintf(textArea1_1Buffer, TEXTAREA1_1_SIZE, "hello %i", x);
textArea1_1.setWildcard(textArea1_1Buffer);
textArea1_1.invalidate();
}
//File: mainScreenView.hpp
//This code runs into Mulitple definition errors....
#ifndef MAINSCREENVIEW_HPP
#define MAINSCREENVIEW_HPP
#include <gui_generated/mainscreen_screen/mainScreenViewBase.hpp>
#include <gui/mainscreen_screen/mainScreenPresenter.hpp>
#include <gui/introscreen_screen/introScreenPresenter.hpp>
#include <../../simulator/msvs/test.h> //trying to include test.h
class mainScreenView : public mainScreenViewBase
{
public:
mainScreenView();
virtual ~mainScreenView() {}
virtual void setupScreen();
virtual void tearDownScreen();
virtual void set_test_X();
virtual void setTestXValue();
protected:
test testx;
};
#endif // MAINSCREENVIEW_HPP
Small section of the error:
Compile
make -f ../gcc/Makefile -j8
Converting images
Compiling TouchGFX/gui/src/mainscreen_screen/mainScreenView.cpp
Compiling TouchGFX/gui/src/mainscreen_screen/mainScreenPresenter.cpp
Compiling TouchGFX/generated/gui_generated/src/common/FrontendApplicationBase.cpp
Compiling TouchGFX/target/BoardConfiguration.cpp
Linking TouchGFX/build/bin/target.elf
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenPresenter.o: In function `test::test()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/include/../../simulator/msvs/test.cpp:5: multiple definition of `test::test()'
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenView.o:c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/include/../../simulator/msvs/test.cpp:5: first defined here
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenPresenter.o: In function `mainScreenPresenter::~mainScreenPresenter()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/include/gui/mainscreen_screen/mainScreenPresenter.hpp:28: multiple definition of `test::test()'
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenView.o:c:\TouchGFXProjects\MyApplication_7/Middlewares/ST/TouchGFX/touchgfx/framework/include/touchgfx/Screen.hpp:213: first defined here
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenPresenter.o: In function `mainScreenPresenter::~mainScreenPresenter()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/include/gui/mainscreen_screen/mainScreenPresenter.hpp:28: multiple definition of `test::~test()'
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenView.o:c:\TouchGFXProjects\MyApplication_7/Middlewares/ST/TouchGFX/touchgfx/framework/include/touchgfx/Screen.hpp:213: first defined here
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenPresenter.o: In function `mainScreenPresenter::~mainScreenPresenter()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/include/gui/mainscreen_screen/mainScreenPresenter.hpp:28: multiple definition of `test::~test()'
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenView.o:c:\TouchGFXProjects\MyApplication_7/Middlewares/ST/TouchGFX/touchgfx/framework/include/touchgfx/Screen.hpp:213: first defined here
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenPresenter.o: In function `mainScreenPresenter::~mainScreenPresenter()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/include/gui/mainscreen_screen/mainScreenPresenter.hpp:28: multiple definition of `test::set_testX(int)'
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenView.o:c:\TouchGFXProjects\MyApplication_7/Middlewares/ST/TouchGFX/touchgfx/framework/include/touchgfx/Screen.hpp:213: first defined here
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenPresenter.o: In function `mainScreenPresenter::~mainScreenPresenter()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/include/gui/mainscreen_screen/mainScreenPresenter.hpp:28: multiple definition of `test::get_testX()'
Any advice?
Thanks.
2020-01-13 02:31 AM
You're including test.cpp from your headerfile where test is declared. Remove that.
#include "test.cpp"
/Martin
2020-01-13 08:56 AM
Right. I tried removing that line and it gives me 'Undefined Reference' errors.
It seems I am not properly defining the class functions....?
Compile
make -f ../gcc/Makefile -j8
Converting images
Compiling TouchGFX/gui/src/mainscreen_screen/mainScreenView.cpp
Compiling TouchGFX/gui/src/mainscreen_screen/mainScreenPresenter.cpp
Compiling TouchGFX/generated/gui_generated/src/common/FrontendApplicationBase.cpp
Compiling TouchGFX/target/BoardConfiguration.cpp
Linking TouchGFX/build/bin/target.elf
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenView.o: In function `mainScreenView::set_test_X()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/src/mainscreen_screen/mainScreenView.cpp:27: undefined reference to `test::get_testX()'
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenView.o: In function `mainScreenView::~mainScreenView()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/include/gui/mainscreen_screen/mainScreenView.hpp:13: undefined reference to `test::~test()'
TouchGFX/build/ST/STM32F769I-DISCO/TouchGFX/gui/src/mainscreen_screen/mainScreenView.o: In function `mainScreenView::mainScreenView()':
c:\TouchGFXProjects\MyApplication_7/TouchGFX/gui/src/mainscreen_screen/mainScreenView.cpp:10: undefined reference to `test::test()'
collect2.exe: error: ld returned 1 exit status
gcc/Makefile:330: recipe for target 'TouchGFX/build/bin/target.elf' failed
make[2]: *** [TouchGFX/build/bin/target.elf] Error 1
gcc/Makefile:326: recipe for target 'generate_assets' failed
make[1]: *** [generate_assets] Error 2
../gcc/Makefile:45: recipe for target 'all' failed
make: *** [all] Error 2
Failed
Failed
2020-01-13 03:24 PM
I think my problem might be that the compiler is not compiling test.cpp...
Is there a way to tell the TouchGFX software to compile test.cpp separately like it compiles the rest of the generated .cpp files?
Do you think this would fix my problem?
Thanks
2020-01-14 02:17 PM
I figured out a solution to this problem.
For future reference, the solution is to tell TouchGFX to compile the .cpp file to include.
I searched through the makefile of the project and realized I did not save my test.cpp and test.h files into the right directory.
In order to tell TouchGFX to compile test.cpp, I needed to put test.cpp into the following directory:
C:\TouchGFXProjects\MyApplication\TouchGFX\gui\src\common
\TouchGFX\gui\src is the directory the TouchGFX software will recursively go through and compile any source code it finds. If you have any .cpp files you want the software to compile, put them in this directory.
2020-01-15 12:29 AM
Glad you solved it. Yes, the makefiles provided with touchgfx will find src/ and include/ folders in the components that have been added to the variable
components :=
If you simply have a folder of source files you want to add you can add them directly to:
source_paths :=