首页 > 解决方案 > 在 Windows 中使 CC=other_cc

问题描述

也许这个问题很愚蠢,但我真的无法找到解决此问题的方法

$ make
x86_64-w64-mingw32-gcc -D OS_WINDOWS_NT -ansi -Wall  -O2 -Wno-long-long -I /usr/include   -c -o main.o main.c
In file included from /usr/include/sys/_pthreadtypes.h:12,
                 from /usr/include/sys/types.h:223,
                 from /usr/include/stdio.h:61,
                 from main.c:5:
/usr/include/sys/cpuset.h:17:30: error: expected expression before ‘/’ token
   17 | #define __CPU_SETSIZE 1024  // maximum number of logical processors tracked
      |                              ^
/usr/include/sys/cpuset.h:19:25: note: in expansion of macro ‘__CPU_SETSIZE’
   19 | #define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS)  // maximum group number
      |                         ^~~~~~~~~~~~~
/usr/include/sys/cpuset.h:26:21: note: in expansion of macro ‘__CPU_GROUPMAX’
   26 |   __cpu_mask __bits[__CPU_GROUPMAX];
      |                     ^~~~~~~~~~~~~~
/usr/include/sys/cpuset.h:19:55: error: expected expression before ‘/’ token
   19 | #define __CPU_GROUPMAX (__CPU_SETSIZE / __NCPUBITS)  // maximum group number
      |                                                       ^
/usr/include/sys/cpuset.h:26:21: note: in expansion of macro ‘__CPU_GROUPMAX’
   26 |   __cpu_mask __bits[__CPU_GROUPMAX];
      |                     ^~~~~~~~~~~~~~
/usr/include/sys/cpuset.h:27:1: warning: no semicolon at end of struct or union
   27 | } cpu_set_t;
      | ^
In file included from /usr/include/errno.h:9,
                 from main.c:8:
/usr/include/sys/errno.h:14: warning: "errno" redefined
   14 | #define errno (*__errno())
      |
In file included from /usr/lib/gcc/x86_64-w64-mingw32/10/include/stddef.h:1,
                 from /usr/include/sys/cdefs.h:47,
                 from /usr/include/stdio.h:35,
                 from main.c:5:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/stddef.h:19: note: this is the location of the previous definition
   19 | #define errno (*_errno())
      |
make: *** [<builtin>: main.o] Error 1

标签: cgccmakefilemingw

解决方案


您的问题是您已将-ansi选项添加到编译行:

x86_64-w64-mingw32-gcc -D OS_WINDOWS_NT -ansi ...

-ansi选项告诉编译器编译您的代码,就好像它是 ANSI C 89 标准代码一样。该版本的标准不支持//单行注释分隔符:它只支持传统/* ... */注释。

但是,您包含的头文件显然希望能够使用//注释。-ansi因此,当您使用这些头文件进行编译时,您不能使用该标志。


推荐阅读