
我正在嘗試在 cygwin32 下使用 mingw32 進行交叉編譯。但是,我收到涉及 float.h 的錯誤
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/winnt.h:16:0,
from /usr/i686-w64-mingw32/sys-root/mingw/include/minwindef.h:146,
from /usr/i686-w64-mingw32/sys-root/mingw/include/windef.h:8,
from /usr/i686-w64-mingw32/sys-root/mingw/include/windows.h:69,
from globals.h:17,
from globals.c:10:
/usr/i686-w64-mingw32/sys-root/mingw/include/float.h:278:57: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
_CRTIMP double __cdecl __MINGW_NOTHROW _chgsign (double _X);
我在這裡找到了一篇有類似問題的文章:
https://www.cygwin.com/ml/cygwin/2003-07/msg00525.html
他們建議更改包含的順序,以便在 gcc float.h 之前找到 mingw float.h。
但是,如果我嘗試像這樣手動包含標頭:
i686-w64-mingw32-gcc -DHAVE_CONFIG_H -I /cygdrive/d/Cygwin32/usr/i686-w64-mingw32/sys-root/mingw/include
使用詳細選項,然後我收到一條訊息,指出我的包含被忽略,因為「它是一個與系統目錄重複的非系統目錄」。
我的猜測是,如果我已經安裝了 mingw 庫和 cygwin 的源代碼,通過調用 i686-w64-mingw32-gcc 會自動包含該目錄,我就是這樣做的。
在編譯器詳細輸出中,我可以按照包含的順序清楚地看到問題。
/usr/lib/gcc/i686-w64-mingw32/4.8.3/include
/usr/lib/gcc/i686-w64-mingw32/4.8.3/include-fixed
/usr/i686-w64-mingw32/sys-root/mingw/include
但是如何將 mingw include 移到 gcc include 前面?
答案1
想通了,您可以使用 gcc 標誌 -nostdinc,然後重新定義包含順序。
不知道為什麼我之前的谷歌搜尋沒有找到它。