Skip to main content
kshin.111
Associate III
February 8, 2020
Question

how write c++ and include c++ lib in stm32CubeIDE?

  • February 8, 2020
  • 2 replies
  • 2135 views

hi

in stm32CubeIDE c++ code and standard lib (#include <iostream> or #include <iostraem.h>) not work.

i test:

'convert C to C++'

make c++ project

use only c++ code in func main() ==> 'bool a = true;'

all test not woke!!!

ya khoda

This topic has been closed for replies.

2 replies

KnarfB
Super User
February 8, 2020

Create a C++ project from scratch. By default, C++ code is valid in .cpp files only. So you need to add your C++ code in a new file, say main_cpp.cpp. To keep the generated code intact (if you like HAL...), add a new header file, say main_cpp.h

#ifndef INC_MAIN_CPP_H_
#define INC_MAIN_CPP_H_
 
#ifdef __cplusplus
extern "C" {
#endif
 
void main_cpp();
 
#ifdef __cplusplus
}
#endif
 
#endif /* INC_MAIN_CPP_H_

and include it in main.c. In main(), right before the while loop in a user code section, call main_cpp();

Implement void main_cpp() in main_cpp.cpp.

> #include <iostream>

C++ streams? Where do you expect the output going to? For POSIX IO, adapt syscalls.c

kshin.111
kshin.111Author
Associate III
February 8, 2020

> #include <iostream>

C++ streams? Where do you expect the output going to? For POSIX IO, adapt syscalls.c

only for add one lib of c++ use of <iostream> :grinning_face_with_sweat:

thank you

Pavel A.
Super User
February 8, 2020

If you want to use bool in C files such as main.c, just #include <stdbool.h>

-- pa