【发布时间】:2021-03-03 12:07:23
【问题描述】:
我安装了MinGW,我写了如下代码测试
#include <stdio.h>
int main() {
#if defined(__WIN32__)
printf("hello win.");
#else
printf("hello unix.");
#endif
return 0;
}
然后编译并运行。
V002294@DESKTOP-A0H4TOJ /c/Users/V002294
$ gcc test.c -o test
V002294@DESKTOP-A0H4TOJ /c/Users/V002294
$ ./test.exe
hello win.
为什么不"hello unix"?
【问题讨论】:
-
因为你的目标平台是win32。
-
我在 Ubuntu 18.04 中运行,我得到了
hello unix。 -
如果我想让Windows平台编译运行并打印“hello unix”,我应该使用Cygwin?
-
运行
which gcc以找出您正在使用的编译器。
标签: c++ c compilation mingw