我有一个C程序;它编译并链接到gcc -std=gnu11 iter.c -o iter
,因为我正在使用一些GNU string.h
扩展名,如strndup
,strnlen
和strsep
。在Linux上用MinGW编译Gnu11 for Windows
我想在Ubuntu Linux上使用软件包i686-w64-mingw32-gcc
来编译该程序。
$ i686-w64-mingw32-gcc -std=gnu11 iter.c -o iter32.exe
In file included from iter.c:1:0:
iter.h: In function ‘str_chomp’:
iter.h:166:15: warning: implicit declaration of function ‘strndup’ [-Wimplicit-function-declaration]
char* new = strndup(str, MAX_STR_LEN);
^
iter.h:166:15: warning: incompatible implicit declaration of built-in function ‘strndup’
iter.h: In function ‘str_split’:
iter.h:189:19: warning: incompatible implicit declaration of built-in function ‘strndup’
*str_copy = strndup(str, MAX_STR_LEN);
^
iter.h:211:26: warning: implicit declaration of function ‘strsep’ [-Wimplicit-function-declaration]
for (i = 0; (token = strsep(&str_copy, delim_str)) != NULL; i++) {
^
iter.h:211:24: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
for (i = 0; (token = strsep(&str_copy, delim_str)) != NULL; i++) {
^
/tmp/ccPH0nG5.o:iter.c:(.text+0x216): undefined reference to `strndup'
/tmp/ccPH0nG5.o:iter.c:(.text+0x2bf): undefined reference to `strndup'
/tmp/ccPH0nG5.o:iter.c:(.text+0x3a7): undefined reference to `strsep'
collect2: error: ld returned 1 exit status
我已经安装了所有必需的MinGW运行时和库,但MinGW的似乎忽视了-std=gnu11
指令。它并不完全忽略该选项,因为-std=asdf
是“无法识别的”,但它拒绝交叉编译GNU C.
有没有一种方法可以使用GNU扩展程序为Windows交叉编译?
如果您正在编译一个依赖Microsoft C运行时库的程序,就像MinGWin程序一样,那么您仅限于该库提供的函数。你应该感谢编译器告诉你这个,而不是在运行时创建一个注定要崩溃的程序。 –
@JohnBollinger不是MinGW“Windows简约GNU”吗?事实上,它是** GCC **,并且GNU的LibC与GCC链接,所以人们会认为这些标头是GNU。 – cat
MinGW提供了许多GNU *程序*,包括GCC,在Windows上本地运行。它不*提供GNU C库,而是依靠微软的。它也依赖于其他一些Windows系统库。这显然是[记录](http://www.mingw.org/),它是有道理的。 –