|
最近在stm系列跑c++
今天捡起swm, 测试了一把。 由于MDK需要microlib支持,资料都说microlib不支持c++, 放弃了在microlib。(也不知道具体是哪些函数,不折腾)
回到GCC 编译器
mynumber.h/c
- #ifndef __MYNUMBER_H
- #define __MYNUMBER_H
- class MyNumber
- {
- public:
- MyNumber();
- int MyAdd(int a, int b);
- };
- #endif
- #include "mynumber.h"
- // MyNumber mynum;
- MyNumber::MyNumber() {};
- int MyNumber::MyAdd(int a, int b)
- {
- return a + b;
- }
复制代码
cpp_start.h/c
- #ifndef __ADD_H
- #define __ADD_H
-
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- int my_add(int a, int b);
- #ifdef __cplusplus
- }
- #endif
- #endif
- #include "cpp_start.h"
- #include "mynumber.h"
- MyNumber mynum;
- int my_add(int a, int b)
- {
- return mynum.MyAdd(a, b);
- }
复制代码
taks
- void test_Task(void *argument)
- {
- for (;;)
- {
- // printf("SystemCoreClock ==>> %d \r\n",SystemCoreClock);
- log_i("MSG : SystemCoreClock ==>> %d \r\n",SystemCoreClock);
- log_i("C++ add %d \r\n", my_add(6,7));
- osDelay(2000);
- }
- }
复制代码 result
- [36;22mI/NO_TAG [] (46 test_Task)MSG : SystemCoreClock ==>> add 13
- [0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
- [36;22mI/NO_TAG [] (45 test_Task)MSG : SystemCoreClock ==>> 120000000
- [0m
- [36;22mI/NO_TAG [] (46 test_Task)MSG : SystemCoreClock ==>> add 13
- [0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
- [36;22mI/NO_TAG [] (45 test_Task)MSG : SystemCoreClock ==>> 120000000
- [0m
- [36;22mI/NO_TAG [] (46 test_Task)MSG : SystemCoreClock ==>> add 13
- [0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
- [36;22mI/NO_TAG [] (45 test_Task)MSG : SystemCoreClock ==>> 120000000
- [0m
- [36;22mI/NO_TAG [] (46 test_Task)MSG : SystemCoreClock ==>> add 13
- [0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
- [36;22mI/NO_TAG [] (55 led_Task)MAIN : ----[0m
复制代码 C++ 可以在swm34 上编译运行(编译器 arm-none-eabi-g++)
|
|