`ios_base' undeclared 错误及解决

本文介绍了在使用较低版本的g++编译器时遇到的“ios_base未声明”错误,并提供了解决方案,即用ios替代ios_base以确保代码能在如Debian Woody等旧版系统上正常编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


 本来可编译的代码,换了个低版本的RedHat就报错: “`ios_base' undeclared (first use this function)”

估计是低版本的g++所配的libstdc++有问题,但不知如何简单的解决。

还好一搜就查到一个帖子: http://mailman.powerdns.com/pipermail/pdns-users/2003-October/000771.html

Hmm, ios_base is defined in the C++ standard, but it isn't supported by g++
2.95.x. You can replace "ios_base" with "ios" to make it compile with g++
2.95.x (that's what I have done to make it compile on Debian woody).
照样改一下就好了。
/****************************************************************************** ** Include Files ******************************************************************************/ #include "system_init.h" #include "Board_GpioCfg.h" /****************************************************************************** ** Private variables ******************************************************************************/ static volatile uint32_t TimingDelay; /******************************************************************************* ** Global Functions *******************************************************************************/ /** * @brief :Initialize the different GPIO ports * @param[in] None * @param[out] None * @retval :None */ // 配置 PORTB 为输出模式 GPIOB->DDR |= 0xFF; // 设置前8位为输出 GPIOB->DR &= ~0xFF; // 设置输出低电平 // 使能 GPIOA 和 GPIOB 的时钟 RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN; void BoardGpioInit(void) { GPIO_Write_Mode_Bits(GPIOA_SFR, GPIO_PIN_MASK_0, GPIO_MODE_OUT); //LED1 GPIO_Write_Mode_Bits(GPIO_SFR, GPIO_PIN_MASK_11, GPIO_MODE_OUT); //LED2 } /** * @brief: Delay time * @param[in] nms * @param[out] None * @retval : None */ void delay_ms(volatile uint32_t nms) { volatile uint32_t i, j; for (i = 0; i < nms; i++) { j = 5000; while (j--) ; } } /******************************************************************************* ** Main Functions *******************************************************************************/ int main() { /* Initialize the system clock is 72MHz*/ SystemInit(72U); /* Setup SysTick Timer as delay function, and input frequency is 72MHz */ systick_delay_init(72U); /* Initialize the user IOs */ BoardGpioInit(); while (1) { //GPIO_Write_Mode_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, GPIO_MODE_OUT); //LED1 //GPIO_Write_Mode_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, GPIO_MODE_OUT); //LED2 //GPIO_Write_Mode_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, GPIO_MODE_OUT); GPIO_Set_Output_Data_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, Bit_SET);//LED1 H //GPIO_Write_Mode_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, GPIO_MODE_OUT); GPIO_Set_Output_Data_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, Bit_SET);//LED1 H systick_delay_ms(200); //GPIO_Write_Mode_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, GPIO_MODE_OUT); GPIO_Set_Output_Data_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, Bit_RESET);//LED1 L //GPIO_Write_Mode_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, GPIO_MODE_OUT); GPIO_Set_Output_Data_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, Bit_SET);//LED2 H systick_delay_ms(200); //GPIO_Write_Mode_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, GPIO_MODE_OUT); GPIO_Set_Output_Data_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, Bit_SET);//LED1 H //GPIO_Write_Mode_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, GPIO_MODE_OUT); GPIO_Set_Output_Data_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, Bit_RESET);//LED2 L systick_delay_ms(200); //GPIO_Write_Mode_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, GPIO_MODE_OUT); GPIO_Set_Output_Data_Bits(GPIOA_SFR, GPIO_PIN_MASK_3, Bit_RESET);//LED1 L //GPIO_Write_Mode_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, GPIO_MODE_OUT); GPIO_Set_Output_Data_Bits(GPIOF_SFR, GPIO_PIN_MASK_11, Bit_RESET);//LED2 L systick_delay_ms(200); } } /** * @brief : Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param[in] file pointer to the source file name * @param[in] line assert_param error line source number * @param[out] None * @retval :None */ void check_failed(uint8_t *File, uint32_t Line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { ; } }; 这段代码编译显示10:14:13 **** Incremental Build of configuration Debug for project GPIO_InputOutput **** gmake -j16 all Building file: ../main.c ../main.c:22:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token ../main.c:23:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token ../main.c:26:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token ../main.c: In function 'BoardGpioInit': ../main.c:31:28: error: 'GPIO_SFR' undeclared (first use in this function) ../main.c:31:28: note: each undeclared identifier is reported only once for each function it appears in gmake: *** [subdir.mk:26: main.o] Error 1 "gmake -j16 all" terminated with exit code 2. Build might be incomplete. 10:14:14 Build Failed. 5 errors, 0 warnings. (took 642ms) 修改正确发给我
最新发布
08-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值