cancel
Showing results for 
Search instead for 
Did you mean: 

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

yum
Associate II

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.

14 REPLIES 14
MVill.11
Associate

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

MVill.11
Associate

 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

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?

Thyrion
Associate

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>

 

 

 

 

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
Up vote any posts that you find helpful, it shows what's working..