这是尝试从源代码编译 Microchip XC32 微控制器 g++ XC32 v4.35 交叉编译器的免许可 GPL 版本的延续。
请参阅我的问答,以及我的存储库:https://github.com/ElectricRCAircraftGuy/Microchip_XC32_Compiler。
请注意,这可以在 Linux Ubuntu 22.04 上完美完成,
gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
。
但是,当在 MSYS2 UCRT64 环境中的 Windows 上使用 gcc --version
gcc.exe (Rev2, Built by MSYS2 project) 13.2.0
进行编译(按照我的说明进行设置)时,我现在在
gcc/gcc/system.h
中收到以下错误:
./../../pic32m-source/gcc/gcc/prefix.c
../../../pic32m-source/gcc/gcc/system.h:737:30: error: expected identifier before string constant
737 | #define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
| ^~~~~~~~
../../../pic32m-source/gcc/gcc/system.h:737:30: error: expected ',' or '...' before string constant
../../../pic32m-source/gcc/gcc/system.h:737:30: error: expected identifier before string constant
737 | #define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
| ^~~~~~~~
../../../pic32m-source/gcc/gcc/system.h:737:30: error: expected ',' or '...' before string constant
make[1]: *** [Makefile:1112: prefix.o] Error 1
make[1]: Leaving directory '/c/Users/gabriel/GS/dev/Microchip_XC32_Compiler/xc32-v4.35-src/pic32m-build/gcc/gcc'
make: *** [Makefile:4290: all-gcc] Error 2
system.h
文件,位于第737行:
/* Redefine abort to report an internal error w/o coredump, and
reporting the location of the error in the source file. */
extern void fancy_abort (const char *, int, const char *)
ATTRIBUTE_NORETURN ATTRIBUTE_COLD;
#define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
abort()
的这个定义正在被调用,例如,在C++模板类中fibonacci_heap.h
第460行,这里:
template<class K, class V>
V*
fibonacci_heap<K,V>::delete_node (fibonacci_node<K,V> *node, bool release)
{
V *ret = node->m_data;
/* To perform delete, we just make it the min key, and extract. */
replace_key (node, m_global_min_key);
if (node != m_min)
{
fprintf (stderr, "Can't force minimum on fibheap.\n");
abort (); // <=========== HERE ===========
}
extract_min (release);
return ret;
}
如何解决此构建错误?
而且,为什么它发生在 Windows 上,而不是 Linux 上?
可能的修复:https://github.com/yosshin4004/xdev68k/blob/main/build_m68k-toolchain.sh#L199-L210
#
# 新しい mingw 環境では以下のようなエラーとなる。
# ../../../src/gcc-10.2.0/gcc/system.h:743:30: error: expected identifier before string constant
# 743 | #define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
# 応急処置として、問題を起こす行を除去する。
# abort() は stdlib.h 内で宣言された実装のままの挙動となる。
#
if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
cat ${SRC_DIR}/${GCC_DIR}/gcc/system.h |\
perl -e 'my $before="#define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)";my $after="/* $before */";$before=quotemeta($before);while(<>){$_=~s/$before/$after/g;print $_;}' > ${SRC_DIR}/${GCC_DIR}/gcc/system.h.tmp;
mv ${SRC_DIR}/${GCC_DIR}/gcc/system.h.tmp ${SRC_DIR}/${GCC_DIR}/gcc/system.h
fi
#
# In the new mingw environment, the following error will occur.
# ../../../src/gcc-10.2.0/gcc/system.h:743:30: error: expected identifier before string constant
# 743 | #define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
# As a workaround, remove the offending line.
# abort() behaves as the implementation declared in stdlib.h.
上面的代码只是在
#define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
中找到 gcc/system.h
,并将其注释为 /* #define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__) */
,从而将其删除。
仅仅注释掉这个有问题的宏定义似乎真的很黑客。我不完全理解这一变化的影响。
只需注释掉
abort()
定义,就像我的问题底部记录的here 那样,就可以了。
Windows 中的 MSYS2 似乎有一个错误,阻止构建使用它定义的工作,因此只需打开
xc32-v4.35-src/pic32m-source/gcc/gcc/system.h
,在第 737 行找到这一行:
#define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
...然后像这样注释掉:
/* #define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__) */
构建现已完成,MSYS2 UCRT64 gcc 工具链能够完成 PIC32 mcu gcc 交叉编译器的构建!