Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
C++_cpp
qemu-vexpress-a9
全局变量
qemu-vexpress-a9 上c++ 全局类的构造函数没有调用
发布于 2021-04-30 13:32:58 浏览:891
订阅该版
win10 qemu-vexpress-a9 环境下面,局部变量的c++能正使用,但全局变量的那些类,构造函数没有调用。cplusplus_system_init函数有调用,__ctors_start__和__ctors_end__地址一样。 ```c RT_WEAK int cplusplus_system_init(void) { #if defined(__CC_ARM) || defined(__CLANG_ARM) /* If there is no SHT$$INIT_ARRAY, calling * $Super$$__cpp_initialize__aeabi_() will cause fault. At least until Keil5.12 * the problem still exists. So we have to initialize the C++ runtime by ourself. */ typedef void PROC(); extern const unsigned long SHT$$INIT_ARRAY$$Base[]; extern const unsigned long SHT$$INIT_ARRAY$$Limit[]; const unsigned long *base = SHT$$INIT_ARRAY$$Base; const unsigned long *lim = SHT$$INIT_ARRAY$$Limit; for (; base != lim; base++) { PROC *proc = (PROC *)((const char *)base + *base); (*proc)(); } #elif defined(__GNUC__) typedef void(*pfunc)(); extern pfunc __ctors_start__[]; extern pfunc __ctors_end__[]; pfunc *p; for (p = __ctors_start__; p < __ctors_end__; p++) (*p)(); #endif return 0; } ``` *main.c* ```c #include
#include
#include
#include "test.h" int main(void) { printf("test: %d\n",test_b()); return 0; } ``` *test.h* ```c int test_b(void); ``` *test.cpp* ```c #include
class B{ public: B(){ printf("B::B()\n"); b = 5; } ~B(){} int b; }; B b; extern "C" int test_b(void){ return b.b; } ``` 结果 ``` PS H:\work\qemu\rt-thread\rt-thread\bsp\qemu-vexpress-a9> .\qemu.bat WARNING: Image format was not specified for 'sd.bin' and probing guessed raw. Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted. Specify the 'raw' format explicitly to remove the restrictions. dsound: Could not initialize DirectSoundCapture dsound: Reason: No sound driver is available for use, or the given GUID is not a valid DirectSound device ID \ | / - RT - Thread Operating System / | \ 4.0.3 build Apr 29 2021 2006 - 2021 Copyright by rt-thread team lwIP-2.0.2 initialized! [32m[I/sal.skt] Socket Abstraction Layer initialize success. m[I/SDIO] SD card capacity 65536 KB. [I/SDIO] switching card to hig h speed failed! file system initialization done! test: 0 msh /> ```
查看更多
2
个回答
默认排序
按发布时间排序
flashman2002
2021-04-30
这家伙很懒,什么也没写!
建议阅读文档:https://www.rt-thread.org/document/site/application-note/components/cplusplus/an0035-cpp/
cxhxy12345
2021-04-30
这家伙很懒,什么也没写!
你这里是不是因该先声明后赋值, class B{ public: B(){ printf("B::B()\n"); int b = 5;//加个声明 } ~B(){} int b;//这里去掉 };
撰写答案
登录
注册新账号
关注者
0
被浏览
891
关于作者
ckk
这家伙很懒,什么也没写!
提问
1
回答
0
被采纳
0
关注TA
发私信
相关问题
1
RT-STUDIO下加入TOUCHGFX?
2
有没有人在RTT上使用C++编程
3
nano c++ 报错如何处理
4
让成员函数能作为rt_device中的回调函数
5
成员函数作为回调函数
6
C++编译问题 undefined reference to `_exit'
7
开启C++功能后,rt_kprintf和单步调试功能无法使用
8
RT-Thread Studio C++ 异常处理 (与预期不一致)
9
C++继承Thread类报错怎么办?
10
STM32使用C++ 编译报错
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
国产MCU移植系列教程汇总,欢迎查看!
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
NXP MCXN947测评(二)ETH设备使用
2
【RA8D1-Vision Board】适配 LVGL V8
3
VISION BOARD 第二弹 基础工程配置和点亮一个LED灯
4
musb移植问题记录【设备注册3次挂起】
5
关于使用CherryUSB时候使用外挂的usb phy 芯片配置的一点注意事项
热门标签
RT-Thread Studio
串口
LWIP
Env
SPI
Bootloader
AT
ART-Pi
Hardfault
CAN总线
FinSH
USB
文件系统
RT-Thread
DMA
SCons
线程
RT-Thread Nano
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
ota在线升级
WIZnet_W5500
I2C_IIC
UART
flash
cubemx
packages_软件包
freemodbus
潘多拉开发板_Pandora
PWM
定时器
ADC
BSP
中断
keil_MDK
编译报错
socket
MicroPython
GD32
msh
Debug
ulog
SDIO总线
SFUD
rt_mq_消息队列_msg_queue
C++_cpp
本月问答贡献
xiaorui
7
个答案
3
次被采纳
sakumisu
4
个答案
3
次被采纳
三世执戟
31
个答案
1
次被采纳
梦笑真美
18
个答案
1
次被采纳
踩姑娘的小蘑菇
14
个答案
1
次被采纳
本月文章贡献
Z_Y
2
篇文章
5
次点赞
Alipay
2
篇文章
3
次点赞
2345vor
2
篇文章
1
次点赞
比特饼干
1
篇文章
6
次点赞
Vangaoven
1
篇文章
3
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部