gpt4 book ai didi

c++ - cstdlib 编译命名空间错误

转载 作者:太空宇宙 更新时间:2023-11-04 13:47:47 25 4
gpt4 key购买 nike

我正在将 cpp 文件从 Windows 8 64 位机器交叉编译到 ARM-Cortex M。一切正常,但当我需要 stdlib 时,它会给我以下错误:

C:\Program Files (x86)\GNU Tools ARM Embedded\4.8 2014q2\arm-none-eabi\include\c++\4.8.4/cstdlib:114:1: error: unknown type name 'namespace'
namespace std _GLIBCXX_VISIBILITY(default)
^
C:\Program Files (x86)\GNU Tools ARM Embedded\4.8 2014q2\arm-none-eabi\include\c++\4.8.4/cstdlib:115:1: error: expected ',' or ';' before '{' token
{
^
In file included from C:/mbed/mbed-src/api/platform.h:27:0,
from C:/mbed/mbed-src/api/mbed.h:21,
from test.cpp:1:
C:\Program Files (x86)\GNU Tools ARM Embedded\4.8 2014q2\arm-none-eabi\include\c++\4.8.4/cstdio:94:1: error: unknown type name 'namespace'
namespace std
^
C:\Program Files (x86)\GNU Tools ARM Embedded\4.8 2014q2\arm-none-eabi\include\c++\4.8.4/cstdio:95:1: error: expected '=', ',', ';', 'asm' or '__attribute__' be
fore '{' token
{
^

我用谷歌搜索了这个,我认为可见性可能会导致 Windows 出现问题,但我不知道如何解决它。我跟踪了消息来源,发现:

# define _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY 1

#if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY
# define _GLIBCXX_VISIBILITY(V) __attribute__ ((__visibility__ (#V)))
#else

我在 c++config.h 文件中找到了它。我完整的 g++ 命令是:

arm-none-eabi-g++ -v -Os -flto -ffunction-sections -fdata-sections -fno-builtin -Wall -Wextra -pipe -fvisibility=hidden -x c -Os -mthumb -mcpu=cortex-m4 -mfloat
-abi=hard -mfpu=fpv4-sp-d16 -fno-inline -DSTM32F401xC -DSTM32F401xx -DNDEBUG -DTOOLCHAIN_GCC_CW=1 -IC:/mbed/mbed-src/api -IC:/mbed/mbed-src/hal -IC:/mbed/mbed-
src/targets/hal/TARGET_STM/TARGET_USTM32 -IC:/mbed/mbed-src/targets/cmsis -IC:/mbed/mbed-src/targets/cmsis/TARGET_STM/TARGET_USTM32 -IC:/mbed/mbed-libs/MicroLC
D -I"C:\Program Files (x86)\GNU Tools ARM Embedded\4.8 2014q2\arm-none-eabi\include\c++\4.8.4" -I"C:\Program Files (x86)\GNU Tools ARM Embedded\4.8 2014q2\arm-n
one-eabi\include\c++\4.8.4\arm-none-eabi" -c test.cpp -o test.o

最佳答案

问题是您使用此编译器标志将代码编译为“C”代码而不是“C++”代码:

-x c

这当然意味着“命名空间”不是一个有效的关键字,因为它只存在于 C++ 中。

尝试将其更改为

-x c++

或者,更好的是,将其删除。 Gcc 通常从文件结尾(.cpp 与 .c)中找出这一点

关于c++ - cstdlib 编译命名空间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25034632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com