cancel
Showing results for 
Search instead for 
Did you mean: 

std::string causing compilation errors

martin salko
Associate II

Hi, I'm writing a simple uart controlled oscillator.

However when Including std::string, basic_string.h and stl_iterator.h causes several errors.

it almost looks like something is not included, like remove_const_t add_const_t etc..

In these errors, GLIBC THROW is used against c++17 spec, it's strange since the project was generated by the STM32CubeIDE, and I'd assume the accompanying library would be compatible with the c++ standard set as default by the same ide.

Errors In question:

c:\st\stm32cubeide_1.12.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\include\c++\10.3.1\bits\stl_iterator.h:2307:26: error: 'remove_const_t' does not name a type
 2307 |     using __iter_key_t = remove_const_t<
      |                          ^~~~~~~~~~~~~~
c:\st\stm32cubeide_1.12.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\include\c++\10.3.1\bits\stl_iterator.h:2319:10: error: 'add_const_t' was not declared in this scope
 2319 |     pair<add_const_t<__iter_key_t<_InputIterator>>,
      |          ^~~~~~~~~~~
c:\st\stm32cubeide_1.12.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\include\c++\10.3.1\bits\stl_iterator.h:2319:22: error: '__iter_key_t' was not declared in this scope; did you mean '__iter_val_t'?
 2319 |     pair<add_const_t<__iter_key_t<_InputIterator>>,
      |                      ^~~~~~~~~~~~
      |                      __iter_val_t
c:\st\stm32cubeide_1.12.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\include\c++\10.3.1\bits\stl_iterator.h:2319:35: error: wrong number of template arguments (1, should be 2)
--ommitted--
c:\st\stm32cubeide_1.12.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\include\c++\10.3.1\bits\basic_string.h:531:27: error: '_RequireAllocator' does not name a type
  531 |       template<typename = _RequireAllocator<_Alloc>>
      |                           ^~~~~~~~~~~~~~~~~
c:\st\stm32cubeide_1.12.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\include\c++\10.3.1\bits\basic_string.h:531:44: error: expected '>' before '<' token
  531 |       template<typename = _RequireAllocator<_Alloc>>
      |                                            ^
--ommitted--
c:\st\stm32cubeide_1.12.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\include\c++\10.3.1\new:126:52: error: ISO C++17 does not allow dynamic exception specifications
  126 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                                    ^~~~~~~~~~~~~~
c:\st\stm32cubeide_1.12.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\include\c++\10.3.1\new:128:54: error: ISO C++17 does not allow dynamic exception specifications
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |          

File that uses std string:

#ifndef __H_FILE
#define __H_FILE
 
#ifdef __cplusplus
  #define EXPORT_C extern "C"
#else
  #define EXPORT_C
#endif
 
EXPORT_C void _main();
EXPORT_C void _onUsart();
 
 
#ifdef __cplusplus
 
#include "stm32l4xx_hal.h"
#include "stm32l4xx_ll_usart.h"
#include "stm32l4xx_ll_gpio.h"
#include "main.h"
#include <string>
 
class main_c
{
private:
    main_c()
    {}
    
public:
    static inline main_c& getInstance()
    {
        static main_c instance;
 
        return instance;
    }
 
    void main(void)
    {
        LL_USART_EnableIT_RXNE(USART2);
        LL_USART_EnableIT_TXE(USART2);
 
        __enable_irq();
 
    	LD3_GPIO_Port->ODR = LD3_GPIO_Port->ODR ^ LD3_Pin;
 
    }
 
    void onUsart(void)
    {
        if (USART2->ISR & USART_ISR_RXNE)
        {
            recieveBuffer += USART2->RDR;
        }
 
        if (USART2->ISR & USART_ISR_TXE)
        {
            if (transmittPointer < transmittBuffer.size())
            {
                USART2->TDR = transmittBuffer[transmittPointer++];
            }
        }
    }
 
    void print(std::string text)
    {
        while (transmittPointer < transmittBuffer.size())
        {}
 
        USART2->TDR = transmittBuffer[transmittPointer++];    
    }
 
    std::string recieveBuffer;
    std::string transmittBuffer;
    size_t transmittPointer = 0;
};
 
#endif
#endif

1 ACCEPTED SOLUTION

Accepted Solutions
martin salko
Associate II

Ah I've figured it out, an added library redefined __cplusplus define, which contains the version of currently used C++.

so glibcxx was configured to the wrong c++ version :p

View solution in original post

1 REPLY 1
martin salko
Associate II

Ah I've figured it out, an added library redefined __cplusplus define, which contains the version of currently used C++.

so glibcxx was configured to the wrong c++ version :p