Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » SW4STM32 (Eclipse based) has some C++/C coexistance problems
SW4STM32 (Eclipse based) has some C++/C coexistance problems [message #1768782] Sun, 23 July 2017 15:52 Go to next message
Eclipse UserFriend
Hello community,

I have recognized here are many experts for compiling problems and here is some experience with SW4STM32.

I want to develop a C++ project for the STM32 microcontroller. So I need to include the C libraries from STM32 into a C++ project.

The C++ in standalone is working and compiling properly, but when adding the C library files, new compling errors appear.

Here are there errors and my files:

My Build console:
18:57:09 **** Incremental Build of configuration Debug for project Mastercontroller_v1 ****
make all 
Building file: ../src/SPI.cpp
Invoking: MCU G++ Compiler
C:\Users\Lennart\OneDrive\Dokumente\STM\Mastercontroller_v1\Debug
arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DNUCLEO_F401RE -DSTM32F4 -DSTM32F401RETx -DSTM32 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F401xE -I""$MyLocation$/inc" -I""$MyLocation$/CMSIS/core" -I""$MyLocation$/CMSIS/device" -I""$MyLocation$/HAL_Driver/Inc/Legacy" -I""$MyLocation$/HAL_Driver/Inc" -I""$MyLocation$/Utilities/STM32F4xx-Nucleo" -O0 -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fno-exceptions -fno-rtti -MMD -MP -MF"src/SPI.d" -MT"src/SPI.o" -o "src/SPI.o" "../src/SPI.cpp"
Finished building: ../src/SPI.cpp
 
Building file: ../src/System.cpp
Invoking: MCU G++ Compiler
C:\Users\Lennart\OneDrive\Dokumente\STM\Mastercontroller_v1\Debug
arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DNUCLEO_F401RE -DSTM32F4 -DSTM32F401RETx -DSTM32 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F401xE -I""$MyLocation$/inc" -I""$MyLocation$/CMSIS/core" -I""$MyLocation$/CMSIS/device" -I""$MyLocation$/HAL_Driver/Inc/Legacy" -I""$MyLocation$/HAL_Driver/Inc" -I""$MyLocation$/Utilities/STM32F4xx-Nucleo" -O0 -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fno-exceptions -fno-rtti -MMD -MP -MF"src/System.d" -MT"src/System.o" -o "src/System.o" "../src/System.cpp"
Finished building: ../src/System.cpp
 
Building file: ../src/main.cpp
Invoking: MCU G++ Compiler
C:\Users\Lennart\OneDrive\Dokumente\STM\Mastercontroller_v1\Debug
arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DNUCLEO_F401RE -DSTM32F4 -DSTM32F401RETx -DSTM32 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F401xE -I""$MyLocation$/inc" -I""$MyLocation$/CMSIS/core" -I""$MyLocation$/CMSIS/device" -I""$MyLocation$/HAL_Driver/Inc/Legacy" -I""$MyLocation$/HAL_Driver/Inc" -I""$MyLocation$/Utilities/STM32F4xx-Nucleo" -O0 -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fno-exceptions -fno-rtti -MMD -MP -MF"src/main.d" -MT"src/main.o" -o "src/main.o" "../src/main.cpp"
Finished building: ../src/main.cpp
 
Building file: ../src/stm32f4xx_hal_msp.c
Invoking: MCU GCC Compiler
C:\Users\Lennart\OneDrive\Dokumente\STM\Mastercontroller_v1\Debug
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DNUCLEO_F401RE -DSTM32F4 -DSTM32F401RETx -DSTM32 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F401xE -I""$MyLocation$/inc" -I""$MyLocation$/CMSIS/core" -I""$MyLocation$/CMSIS/device" -I""$MyLocation$/HAL_Driver/Inc/Legacy" -I""$MyLocation$/HAL_Driver/Inc" -I""$MyLocation$/Utilities/STM32F4xx-Nucleo" -O0 -g3 -Wall -fmessage-length=0 -ffunction-sections -c -MMD -MP -MF"src/stm32f4xx_hal_msp.d" -MT"src/stm32f4xx_hal_msp.o" -o "src/stm32f4xx_hal_msp.o" "../src/stm32f4xx_hal_msp.c"
In file included from "$MyLocation$/inc/Includes.hpp:19:0,
                 from ../src/stm32f4xx_hal_msp.c:40:
"$MyLocation$/inc/System.hpp:13:1: error: unknown type name 'class'
 class System{
 ^
"$MyLocation$/inc/System.hpp:13:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 class System{
             ^
In file included from "$MyLocation$/inc/Includes.hpp:20:0,
                 from ../src/stm32f4xx_hal_msp.c:40:
"$MyLocation$/inc/SPI.hpp:14:1: error: unknown type name 'class'
 class SPI
 ^
"$MyLocation$/inc/SPI.hpp:15:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
make: *** [src/stm32f4xx_hal_msp.o] Error 1

18:57:14 Build Finished (took 4s.912ms)



main.cpp
/*
 * main.cpp
 *
 *  Created on: 22.07.2017
 *      Author: Lennart
 */

#include <Includes.hpp>

int main(void)
{

	for(;;);
}



SPI.cpp
/*
 * SPI.cpp
 *
 *  Created on: 21.07.2017
 *      Author: Lennart
 */

#include "SPI.hpp"

SPI::SPI()
{

}

void SPI::initializeSPI(){
	  SpiHandle.Instance               = SPI1;
	  SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
	  SpiHandle.Init.Direction         = SPI_DIRECTION_2LINES;
	  SpiHandle.Init.CLKPhase          = SPI_PHASE_1EDGE;
	  SpiHandle.Init.CLKPolarity       = SPI_POLARITY_HIGH;
	  SpiHandle.Init.CRCCalculation    = SPI_CRCCALCULATION_DISABLE;
	  SpiHandle.Init.CRCPolynomial     = 7;
	  SpiHandle.Init.DataSize          = SPI_DATASIZE_8BIT;
	  SpiHandle.Init.FirstBit          = SPI_FIRSTBIT_MSB;
	  SpiHandle.Init.NSS               = SPI_NSS_SOFT;
	  SpiHandle.Init.TIMode            = SPI_TIMODE_DISABLE;

	  SpiHandle.Init.Mode = SPI_MODE_SLAVE;

	  if(HAL_SPI_Init(&SpiHandle) != HAL_OK)
	  {
	    System::getInstance()->ErrorHandler();
	  }
}




SPI.hpp
/*
 * SPI.hpp
 *
 *  Created on: 21.07.2017
 *      Author: Lennart
 */

#ifndef SPI_HPP_
#define SPI_HPP_

#include "includes.hpp"

class SPI
{
private:
	SPI_HandleTypeDef SpiHandle;

public:
	SPI();
	void initializeSPI();
};







#endif /* SPI_HPP_ */




Maybe someone has an idea about what I am doing wrong.


Thanks for every reply :)
Lennart
Re: SW4STM32 (Eclipse based) has some C++/C coexistance problems [message #1768874 is a reply to message #1768782] Mon, 24 July 2017 10:24 Go to previous messageGo to next message
Eclipse UserFriend
Looks like "../src/stm32f4xx_hal_msp.c" a C file, is including C++ code (in the form of an hpp file) as the error is about class.

Try not mixing C++ and C in a single compilation unit.
Re: SW4STM32 (Eclipse based) has some C++/C coexistance problems [message #1768887 is a reply to message #1768874] Mon, 24 July 2017 11:21 Go to previous message
Eclipse UserFriend
Oh...

Yes thats right. It is obvious but was not clear to me.

Thank you very much :)
Previous Topic:How do I create a simple shared object library in C
Next Topic:unable to start correctly
Goto Forum:
  


Current Time: Mon Apr 14 18:01:02 EDT 2025

Powered by FUDForum. Page generated in 0.03499 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top