c - 为什么我在编译程序时会出现这个错误?
问题描述
我正在尝试在linux OS 中编译 c 文件,但我遇到了很多错误。我在互联网上搜索并找到了安装 mingw-w64 的解决方案。我安装了但得到同样的错误。
这是我的第一个.c 文件:
#include<stdio.h>
int main()
{
printf("Hello world");
return 0;
}
这是我编译后得到的:
┌──(rootkali)-[/home/dj/Desktop/c/graphics]
└─# gcc first.c -o output 1 ⚙
In file included from /usr/local/include/corecrt.h:10,
from /usr/local/include/corecrt_stdio_config.h:10,
from /usr/local/include/stdio.h:9,
from first.c:1:
/usr/local/include/_mingw.h:272:2: error: #error Only Win32 target is supported!
272 | #error Only Win32 target is supported!
| ^~~~~
In file included from /usr/local/include/corecrt.h:10,
from /usr/local/include/corecrt_stdio_config.h:10,
from /usr/local/include/stdio.h:9,
from first.c:1:
/usr/local/include/_mingw.h:580:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__debugbreak’
580 | void __cdecl __debugbreak(void);
| ^~~~~~~~~~~~
/usr/local/include/_mingw.h:581:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__debugbreak’
581 | __MINGW_INTRIN_INLINE void __cdecl __debugbreak(void)
| ^~~~~~~~~~~~
In file included from first.c:1:
/usr/local/include/stdio.h:93:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__acrt_iob_func’
93 | _CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index);
| ^~~~~~~~~~~~~~~
/usr/local/include/stdio.h:158:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_sscanf’
158 | int __cdecl __mingw_sscanf(const char * __restrict__ _Src,const char * __restrict__ _Format,...);
| ^~~~~~~~~~~~~~
/usr/local/include/stdio.h:161:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vsscanf’
161 | int __cdecl __mingw_vsscanf (const char * __restrict__ _Str,const char * __restrict__ Format,va_list argp);
...
/usr/local/include/sec_api/stdio_s.h:857:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_vscwprintf_l’
857 | _CRTIMP int __cdecl _vscwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
| ^~~~~~~~~~~~~
/usr/local/include/sec_api/stdio_s.h:858:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_fwscanf_l’
858 | _CRTIMP int __cdecl _fwscanf_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...);
| ^~~~~~~~~~
/usr/local/include/sec_api/stdio_s.h:859:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_swscanf_l’
859 | _CRTIMP int __cdecl _swscanf_l(const wchar_t *_Src,const wchar_t *_Format,_locale_t _Locale,...);
| ^~~~~~~~~~
/usr/local/include/sec_api/stdio_s.h:860:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_snwscanf_l’
860 | _CRTIMP int __cdecl _snwscanf_l(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...);
| ^~~~~~~~~~~
/usr/local/include/sec_api/stdio_s.h:861:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_wscanf_l’
861 | _CRTIMP int __cdecl _wscanf_l(const wchar_t *_Format,_locale_t _Locale,...);
| ^~~~~~~~~
first.c:4:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
4 | {
| ^
first.c:7: error: expected ‘{’ at end of input
7 | }
|
请帮我解决这个问题。
提前致谢
解决方案
Mingw-w64 编译器适用于 Windows。如果您使用的是 linux,那么您只需要安装gcc
应该已经预先安装在您的系统上的那个。只需删除 mingw 包,它应该可以工作。
推荐阅读
- c# - 是否可以禁用 DataGridView 中单个列的交替行?
- angular5 - Obervable.create 未在 angular5 中使用 ngrx 触发
- php - 将 PDF 下载到浏览器
- linux-kernel - 在 Linux 中检查进程的堆栈使用情况
- azure - 如何集成驻留在不同 Azure B2c 租户中的两个 WebApp 以获得单点登录体验?
- javascript - 将数据复制到剪贴板而不选择任何文本
- javascript - 如何复制仅保留当前道具的对象?
- karate - 如何在空手道框架中设置代理
- c# - 除以两位小数并将结果转换为 int
- arrays - 在matlab中加载stl文件并转换为3D数组