错误:为函数__THROW __asm提供了初始化程序

我正在尝试移植要使用x86_64 C ++编译的ARM-C库,并且出现以下错误:

In file included from /usr/include/c++/5/cwchar:44:0,from /usr/include/c++/5/bits/postypes.h:40,from /usr/include/c++/5/bits/char_traits.h:40,from /usr/include/c++/5/string:40,from MyFile.h:19,/usr/include/wchar.h:226:20: error: initializer provided for function
       __THROW __asm ("wcschr") __attribute_pure__;
                     ^

其中 MyFile.h 具有以下结构

// comments
#pragma once
// comments
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string>              //<<< line 19

…

最初,它给了我一个类似的错误,而不是过去:

In file included from MyFile.h:19:
/usr/include/string.h:73:21: error: initializer provided for function
          __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
                        ^

编译器版本:

GNU C++14 (Ubuntu 5.4.0-6ubuntu1~16.04.11) version 5.4.0 20160609 (x86_64-linux-gnu)
           compiled by GNU C version 5.4.0 20160609,GMP version 6.1.0,MPFR version 3.1.4,MPC version 1.0.3
ldd (Ubuntu GLIBC 2.23-0ubuntu11) 2.23

编译标志:

#g++ -O3 -std=c++14 -fpermissive -Wno-system-headers -w

更新1:

我一直在修改Makefile,原始版本包含$@.via。例如:

@$(COMPILE) -M -MF $(subst .o,.d.tmp,$@) -MT $@ -E $(C_flaGS) $@.via $< -o $@.preprocessed.c

,我将$@.via更改为@$@.via,因为我看到他们在一个较旧的项目中这样做。但是,如果我以$@.via的身份离开,我只会得到:

SomeFile.c:1:1 fatal error: OneHeader.h: No such file or directory

我开始认为我的Makefile错了……

我误解了编译器选项...上面几行,我的makefile通过{strong> DEFInes INCLUDES

创建了@.via文件
       @echo $(patsubst %,'%',$(C_DEFInes)) > $@.via
       @echo $(C_INCLUDE) >> $@.via

和那些@.via文件作为附加参数传递给编译。尽管armcc支持see here--via,但我发现对于g ++-根据gcc doc-,语法为@<your_file>。因此,@$@.via所做的只是将$@.via解析为<your_file>.via

现在我仍然收到initializer provided for function错误消息。

更新2:

我找到了问题,并解释了答案部分中发生的情况。参见下文。

Asongze123456789 回答:错误:为函数__THROW __asm提供了初始化程序

根本原因

此问题的产生是因为我重新定义了__asm而不被任何内容替换(例如#define __asm),因为我还不想接触汇编代码。请记住,我曾说过将ARM移植到x86,所以我认为摆脱编译错误的最简单方法是删除所有__asm指令,但不考虑这样做的影响。

换句话说,当我包含string.h标头时,标头本身使用程序集调用作为指出的错误提示:

/usr/include/wchar.h:226:20: error: initializer provided for function
       __THROW __asm ("wcschr") __attribute_pure__;

,当预处理器将__asm("wcschr")的{​​{1}}更改为("wcschr")时,编译器将遇到错误-这很有意义。

历史道德

请勿重新定义限定符,因为它还会影响您没有直接看到的其他模块,并且更喜欢创建一个宏来更改它们(例如,__asm/*__asm*/)或只运行{{1} }在您的代码库中。

本文链接:https://www.f2er.com/3165013.html

大家都在问