打开Support C++ features后编译失败

发布于 2018-12-11 23:14:28
移植一个开源项目,想把它的操作系统换成rtthread。它是用c++写的,所以我尝试了下rtthread的c++组件,打开后编译失败,具体信息如下:

rthread分支:stable-v3.0.x
commit id: 60265d9
bsp: stm32f4xx-HAL

通过env配置,打开了如下选项:
Support C++ features
Enable libc APIs from toolchain
Enable pthreads APIs

编译的错误提示如下:

Error in calling:
g++ -o "build\kernel\components\cplusplus\crt.o" -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -std=c99 -Dgcc -O0 -gdwarf-2 -g -DHAVE_CCONFIG_H -DSTM32F407xx -DUSE_HAL_DRIVER -DRT_USING_NEWLIB -I. -Iapplications -Idrivers -ILibraries\CMSIS\Device\ST\STM32F4xx\Include -ILibraries\CMSIS\Include -ILibraries\STM32F4xx_HAL_Driver\Inc -IE:\Embedded\RT-Thread\src\rt-thread\include -IE:\Embedded\RT-Thread\src\rt-thread\libcpu\arm\cortex-m4 -IE:\Embedded\RT-Thread\src\rt-thread\libcpu\arm\common -IE:\Embedded\RT-Thread\src\rt-thread\components\cplusplus -IE:\Embedded\RT-Thread\src\rt-thread\components\drivers\include -IE:\Embedded\RT-Thread\src\rt-thread\components\drivers\include -IE:\Embedded\RT-Thread\src\rt-thread\components\drivers\include -IE:\Embedded\RT-Thread\src\rt-thread\components\finsh -IE:\Embedded\RT-Thread\src\rt-thread\components\libc\compilers\newlib -IE:\Embedded\RT-Thread\src\rt-thread\components\libc\pthreads -IE:\Embedded\RT-Thread\src\rt-thread\components\libc\time "E:\Embedded\RT-Thread\src\rt-thread\components\cplusplus\crt.cpp"
Exception: [Error 2] : No such file or directory
scons: *** [build\kernel\components\cplusplus\crt.o] Error 2
scons: building terminated because of errors.


E:\Embedded\RT-Thread\src\rt-thread\components\cplusplus\crt.cpp是存在的,不知它为啥提示没有文件或者目录。

我编译的是stm32f4的程序,我看它用的是g++来编译crt.cpp。编译.c文件时是没问题的,用的是arm-none-eabi-gcc,估计是没配置c++编译器吧。
我看rtconfig.py中是有配置CC,如下:
PREFIX = 'arm-none-eabi-'
CC = PREFIX + 'gcc'


我在CC那行下面配置CXX
CXX = PREFIX + 'g++'

编译的时候,依然使用g++。一脸懵,求解。


查看更多

关注者
0
被浏览
1.1k
5 个回答
yqiu
yqiu 2018-12-12
可以参考下 qemu-vexpress-a9 这个 BSP,默认已经打开 C++ 功能了。
yqiu
yqiu 2018-12-12
这确实是个 bug,在 qemu-vexpress-a9 BSP 下,能够正确使用 arm-none-eabi-g++ 来编译,所以没问题。在 stm32f4xx-HAL BSP 下,使用了 g++ 来进行编译,所以出问题。
wenbodong
wenbodong 2018-12-13
yqiu 发表于 2018-12-12 09:12
这确实是个 bug,在 qemu-vexpress-a9 BSP 下,能够正确使用 arm-none-eabi-g++ 来编译,所以没问题。在 st ...


多谢,参考后如下修改即可

diff --git a/bsp/stm32f4xx-HAL/SConstruct b/bsp/stm32f4xx-HAL/SConstruct
index ea1e8bf..fd53cb3 100644
--- a/bsp/stm32f4xx-HAL/SConstruct
+++ b/bsp/stm32f4xx-HAL/SConstruct
@@ -20,6 +20,7 @@ TARGET = 'rtthread-stm32f4xx.' + rtconfig.TARGET_EXT
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
+ CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)

diff --git a/bsp/stm32f4xx-HAL/rtconfig.py b/bsp/stm32f4xx-HAL/rtconfig.py
index d8de63d..61ae97f 100644
--- a/bsp/stm32f4xx-HAL/rtconfig.py
+++ b/bsp/stm32f4xx-HAL/rtconfig.py
@@ -35,6 +35,7 @@ if PLATFORM == 'gcc':
# tool-chains
PREFIX = 'arm-none-eabi-'
CC = PREFIX + 'gcc'
+ CXX = PREFIX + 'g++'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
@@ -46,7 +47,7 @@ if PLATFORM == 'gcc':
DEVICE = ' -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections'
CFLAGS = DEVICE + ' -std=c99 -Dgcc' # -D' + PART_TYPE
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -Wa,-mimplicit-it=thumb '
- LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-stm32.map,-cref,-u,Reset_Handler -T stm32_rom.ld'
+ LFLAGS = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread-stm32.map,-cref,-u,Reset_Handler -T stm32_rom.ld'

CPATH = ''
LPATH = ''
@@ -57,6 +58,8 @@ if PLATFORM == 'gcc':
else:
CFLAGS += ' -O2'

+ CXXFLAGS = CFLAGS + ' -Woverloaded-virtual -fno-exceptions -fno-rtti'
+
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'

elif PLATFORM == 'armcc':

diff --git a/bsp/stm32f4xx-HAL/stm32_rom.ld b/bsp/stm32f4xx-HAL/stm32_rom.ld
index aa9c9b2..1303f53 100644
--- a/bsp/stm32f4xx-HAL/stm32_rom.ld
+++ b/bsp/stm32f4xx-HAL/stm32_rom.ld
@@ -60,6 +60,23 @@ SECTIONS
_sidata = .;
} > CODE
__exidx_end = .;
+
+ . = ALIGN(4);
+ .ctors :
+ {
+ PROVIDE(__ctors_start__ = .);
+ KEEP(*(SORT(.ctors.*)))
+ KEEP(*(.ctors))
+ PROVIDE(__ctors_end__ = .);
+ } > CODE
+
+ .dtors :
+ {
+ PROVIDE(__dtors_start__ = .);
+ KEEP(*(SORT(.dtors.*)))
+ KEEP(*(.dtors))
+ PROVIDE(__dtors_end__ = .);
+ } > CODE

/* .data section which is used for initialized data */
yqiu
yqiu 2018-12-14
wenbodong,可以直接提个 PR 到 github 上,这也是对社区的贡献。
wenbodong
wenbodong 2018-12-15
yqiu 发表于 2018-12-14 10:01
wenbodong,可以直接提个 PR 到 github 上,这也是对社区的贡献。


我看了几个其他的分支,都存在这个问题。我先试着提交我用的这个分支哈,第一次提交,先学习下流程。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友