我正在尝试移植要使用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
我一直在修改Makefile
,原始版本包含[email protected]
。例如:
@$(COMPILE) -M -MF $(subst .o,.d.tmp,$@) -MT $@ -E $(C_FLAGS) [email protected] $< -o [email protected]
并且我将[email protected]
更改为@[email protected]
,因为我看到他们在一个较旧的项目中这样做。但是,如果我以[email protected]
的身份离开,则会得到:
SomeFile.c:1:1 fatal error: OneHeader.h: No such file or directory
我开始认为我的Makefile
出问题了...
我误解了编译器选项...上面几行,我的makefile通过[[DEFINES和INCLUDES
创建@.via
文件 @echo $(patsubst %, '%', $(C_DEFINES)) > [email protected]
@echo $(C_INCLUDE) >> [email protected]
并且那些@.via
文件作为附加参数传递给编译。虽然armcc
支持--via
,但我发现对于g ++-根据see here-的语法是gcc doc。因此,@<your_file>
所做的只是将@[email protected]
解析为[email protected]
。现在我仍然收到
<your_file>.via
错误消息。更新2:
我发现了问题,并解释了答案部分中发生的情况。见下文。
initializer provided for function
重新定义为什么都不能替换(例如__asm
)。记住,我曾说过将ARM移植到x86,所以我认为摆脱编译错误的最简单方法是删除所有这些#define __asm
指令,但不考虑这样做的后果。换句话说,当我包含__asm
标头时,标头本身使用程序集调用作为指出的错误消息:
string.h
并且当预处理程序将/usr/include/wchar.h:226:20: error: initializer provided for function __THROW __asm ("wcschr") __attribute_pure__;
的__asm("wcschr")
更改时,编译器会遇到错误-这是有道理的。历史道德
不要重新定义限定符,因为它也会影响您没有直接看到的其他模块,而是希望创建一个宏来更改它们(例如,
("wcschr")
代替__asm
),或者只在代码库中运行/*__asm*/
。] >