Skip to main content
yum
Associate II
January 16, 2019
Solved

It is an error that "main" is not defined in "bl main" command.

  • January 16, 2019
  • 14 replies
  • 12345 views

I attach examples and unselected examples of the "Do not generate the main" option of the Application Structure in the Project Manger of STM32CubeMX.

In both cases, when TrueStudio is compiled, an error occurs in startup_stm32f769xx.s in the "startup" folder.

The error is "undefined reference to 'main'".

It is an error that "main" is not defined in "bl main" command.

I want to know how to fix this error.

This topic has been closed for replies.
Best answer by Mon2

@yum​ , TrueStudio at this time is not well integrated into this toolchain and you will see similar error codes.

Can you switch to IAR or SW4STM32 compilers?

Review this webpage:

https://touchgfx.zendesk.com/hc/en-us/articles/360020208091-Configuring-STM32F769I-DISCO

14 replies

AvaTar
Senior III
January 16, 2019

> I attach examples and unselected examples of the "Do not generate the main" option of the Application Structure in the Project Manger of STM32CubeMX.

I don't know Cube well, but that surely means you want/need to provide your own main() function, instead of a Cube-generated one.

A function named main() is defined as the entry point of the application, and startup code across all platform assumes this name.

You can chenge the startup code, and replace "main" with a different label. If your application contains the same label/function.

yum
yumAuthor
Associate II
January 16, 2019

Thank you for answer.

I changed "main.cpp" to "new_main.cpp".

However, an error occurs even if the "bl main" of the strartup code is set to "bl new_main".

AvaTar
Senior III
January 16, 2019

> I changed "main.cpp" to "new_main.cpp".

The name of the source file itself does not matter to the linker.

A function of the name "main" is required.

C++ is a different matter - the linker uses name mangling to differ between overloaded functions. The full declaration (parameters, return value) matters as well. Not sure how TrueStudio handles this.

Mon2
Mon2Best answer
Senior III
January 16, 2019

@yum​ , TrueStudio at this time is not well integrated into this toolchain and you will see similar error codes.

Can you switch to IAR or SW4STM32 compilers?

Review this webpage:

https://touchgfx.zendesk.com/hc/en-us/articles/360020208091-Configuring-STM32F769I-DISCO

yum
yumAuthor
Associate II
January 17, 2019

Thank you for answer.

The IAR compiler does not have a purchase plan.

TureStudio is free so I tried to use it.

I will try SW4STM32 if possible.

Unfortunately, I hope I can use it in TureStudio.

zul-a
Visitor II
April 13, 2019

Hi @yum​ and @Mon2​ 

I am having same problem. Please see attached. I am trying to generate a project via Cube MX for Attolic True studio with Touch Gfx interface. I am using STM32F746G-DISCO board. Any ideas where things are going wrong?

Thanks for the help.

Regards

Zain

Mon2
Senior III
April 13, 2019

Hi @zul-a​ , I am in Hong Kong at this time and do not have full remote access to my lab setup so here are some quick comments:

1) The tool integration is broken so you are facing the observed issues

2) Review the following possible work arounds (in no particular order of preference):

Plan A:

Review the following webpage:

https://community.st.com/s/question/0D70X0000076dLS/guides-for-using-touchgfx-410-with-cubemx-50-known-limitations?s1oid=00Db0000000YtG6&s1nid=0DB0X000000DYbd&emkind=chatterCommentNotification&s1uid=0050X000007vr0X&emtm=1550748757318&fromEmail=1&s1ext=0

and note specifically that you must select V2.0 template from the TouchGFX toolchain.

For this method, you are launching the Touchgfx toolchain FIRST -> select v2.0 template for this target kit -> create your GUI -> compile and test with the simulator -> reflash your target kit and verify it works correctly.

Then proceed to locate the file folder built from this toolchain and launch the CubeMX tool. Suspecting that any code wizard use inside CubeMX will currently break the generated code so you must review the following to fix the broken code:

For use with IAR & STM32F746 Discovery Kit:

https://touchgfx.zendesk.com/hc/en-us/articles/360019884752-Configuring-STM32F746G-DISCO

PS: Do try to run with IAR (if you have it as-is before fixing the code using the above link).

From our experience of investing about a month into these tools with daily long hours, IAR is the most stable compiler to use for integrating these tools till all is fixed by ST in the future.

Plan B: Review the notes from @BBenn​  on how to use the same kit with Atollic on the same landing page.

Plan C: Review the document from @Clark Sann​ on how to get this kit working using the SW4STM32 compiler:

https://community.st.com/s/question/0D50X0000AAHSjZSQX/how-to-get-a-working-touchgfx-project-working-with-stm32f746gdisco-board-and-sw4stm32

As noted a few times, the forum search engine requires some improvement to locate some of these gems of articles.

Hope this helps.

PS: For future readers, please post your update on using this kit and resolution.

zul-a
Visitor II
April 14, 2019

@Mon2​  Thanks a lot for your quick and very detailed response. Would definitely give this a go.

@Amel NASRI​ Any idea by when can we expect to have Cube MX generate bug free code for Atollic TS and Touch Gfx.

Thanks

Zain

MVill.11
Visitor II
October 14, 2020

If you want to use cpp, do not forget to select cpp when using STM32CubeMX for the Target Languge. If you forget to select cpp and rename main.c to main.cpp , then you will get "bl main" error.

Miguel

BSunw.1
Associate III
June 15, 2021

I am using STM32CubeIDE for a STM32MP157C-DK2 project and selected c++ as the targeted language but it still creates a main.c and gives me errors about including classes. Then when I try to change main.c to main.cpp, I get this "bl main" error. Should I be doing something else to make this a usable c++ project?

MVill.11
Visitor II
October 18, 2020

 This problem appears when main.c is changed to main.cpp and error is reported in file “startup_stm32f411ceux.s�? bl main (simply, main.cpp is ignored)

Also it appears randomly (on/off) when creating a new project from File→New→STM32 Project from an Existing STM32CubeMX Configuration File (.ioc). I was fortunate to have one project without the problem (original) and one generated with the .ioc file.

After swapping all files from the good project to the bad one, the problem got fixed when I changed the “.project�? file.

I copied all files from one project to the other directory by directory, but when I copied “.cproject�? , “.mxproject “and “.project�?, I opened these files with a text editor and edited the correct name in all locations needed for the project, before testing.

I found out the bad “.project�? file was missing <nature>org.eclipse.cdt.core.ccnature</nature> in line 25 in the file and when I added this line, the problem went away

In my opinion this problem is created when STM32CubeMX first creates the project and misses this line, randomly.

Note that I made sure that I selected the cpp option before creating the project.

I hope this helps,

Miguel

Visitor II
October 30, 2023

Hello,

I have the same problem, have to create a second main in .cpp to use with CppUTest (i disable the other one in the build configuration)

" ../Core/Startup/startup_stm32h733zgtx.S:99: undefined reference to `main'"

In the .S startup file :

/* Call the application's entry point.*/
 bl main

main is undefined.

My .project seems fine (i have the ccnature) :

 

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>Toto</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
			<triggers>clean,full,incremental,</triggers>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
			<triggers>full,incremental,</triggers>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature>
		<nature>com.st.stm32cube.ide.mcu.MCUCubeProjectNature</nature>
		<nature>org.eclipse.cdt.core.cnature</nature>
		<nature>com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature</nature>
		<nature>com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature</nature>
		<nature>com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature</nature>
		<nature>com.st.stm32cube.ide.mcu.MCURootProjectNature</nature>
		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
		<nature>org.eclipse.cdt.core.ccnature</nature>
	</natures>
</projectDescription>

 

 

 

 

Tesla DeLorean
Guru
October 30, 2023

For C++ / .cpp you need to be aware of Name Mangling

If you want C / Assembler linkage use extern "C" to ensure the name is visible in the name space.

 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..