Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
C++_cpp
qemu-vexpress-a9
全局变量
qemu-vexpress-a9 上c++ 全局类的构造函数没有调用
发布于 2021-04-30 13:32:58 浏览:808
订阅该版
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
被浏览
808
关于作者
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
五分钟玩转RT-Thread新社区
5
国产MCU移植系列教程汇总,欢迎查看!
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
ulog组件多端绑定的demo案例
2
记录rt-thread消息队列的调试方法
3
AT32的ADC使用
4
aht10 终端:The aht10 is under an abnormal status
5
github高阶加速,速度可达带宽峰值,测试到146Mbit/s
热门标签
RT-Thread Studio
串口
LWIP
Env
AT
SPI
Bootloader
FinSH
ART-Pi
CAN总线
Hardfault
USB
文件系统
RT-Thread
DMA
SCons
线程
MQTT
RT-Thread Nano
STM32
RTC
rt-smart
ESP8266
flash
ota在线升级
WIZnet_W5500
FAL
I2C
packages_软件包
UART
cubemx
freemodbus
潘多拉开发板_Pandora
定时器
BSP
PWM
ADC
socket
中断
rt_mq_消息队列_msg_queue
keil_MDK
SDIO
Debug
AB32VG1
MicroPython
编译报错
C++_cpp
msh
ulog
QEMU
本月问答贡献
出出啊
1501
个答案
338
次被采纳
小小李sunny
1390
个答案
276
次被采纳
张世争
715
个答案
157
次被采纳
crystal266
522
个答案
153
次被采纳
whj467467222
1216
个答案
146
次被采纳
本月文章贡献
出出啊
1
篇文章
12
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
2
篇文章
2
次点赞
crystal266
2
篇文章
5
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部