头文件中的代码似乎会导致编译错误

M_M*_*M_M 2 c linux compiler-errors header-files

我有一个CLI程序,该程序由一个vt.c文件组成,该文件可以使用Open Watcom在Windows(cmd.exe)下编译并运行。我还可以在Windows上运行Open Watcom时为Linux编译它(并且生成的版本在Linux下运行)。

但是,当我尝试在linux下编译它时(使用make,它调用cc),我收到375行错误消息。以下是其中一些,其中许多后续错误类似,我只粘贴了前几个:

In file included from vt.c:4:0:
process.h: In function ‘__declspec’:
process.h:45:22: error: storage class specified for parameter ‘execl’
process.h:46:1: error: expected declaration specifiers before ‘__declspec’
process.h:47:1: error: expected declaration specifiers before ‘__declspec’
...
In file included from vt.c:5:0:
ctype.h:48:1: warning: empty declaration
ctype.h:81:37: error: storage class specified for parameter ‘__ctype_b_loc’
ctype.h:82:6: warning: ‘__nothrow__’ attribute ignored
ctype.h:83:28: error: storage class specified for parameter ‘__ctype_tolower_loc’
ctype.h:84:6: warning: ‘__nothrow__’ attribute ignored
ctype.h:85:28: error: storage class specified for parameter ‘__ctype_toupper_loc’
ctype.h:86:6: warning: ‘__nothrow__’ attribute ignored
...
In file included from vt.c:6:0:
string.h:44:14: error: storage class specified for parameter ‘memcpy’
string.h:46:6: warning: ‘__nothrow__’ attribute ignored
string.h:49:14: error: storage class specified for parameter ‘memmove’
string.h:50:6: warning: ‘__nothrow__’ attribute ignored
string.h:57:14: error: storage class specified for parameter ‘memccpy’
string.h:59:6: warning: ‘__nothrow__’ attribute ignored
...
vt.c:28:1: warning: empty declaration
vt.c:41:1: warning: empty declaration
vt.c:50:1: error: parameter ‘maxtextlength’ is initialized
vt.c:70:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
vt.c:123:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
vt.c:158:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
...
vt.c:67:6: error: declaration for parameter ‘clearinputbuffer’ but no such parameter
vt.c:66:6: error: declaration for parameter ‘clrscr’ but no such parameter
vt.c:65:6: error: declaration for parameter ‘testrandom’ but no such parameter
...
string.h:579:14: error: declaration for parameter ‘stpncpy’ but no such parameter
...
ctype.h:268:12: error: declaration for parameter ‘toupper_l’ but no such parameter
...
process.h:45:22: error: declaration for parameter ‘execl’ but no such parameter
vt.c:608:1: error: expected ‘{’ at end of input
make: *** [vt] Error 1
Run Code Online (Sandbox Code Playgroud)

我的问题是,正如(我确定)许多人以前遇到的那样:我只希望它可以编译。

问题3641178似乎暗示了包含文件的顺序很重要,但是出现错误的标头出现在vt.c中的所有其他包含文件之后。

我尝试在Linux上安装Open Watcom,并且提供的头文件相同。据我所知,这些是标准头文件,我无法认为它们会引起编译错误。

如果有人能对此有所启示,我将不胜感激。可以在我的git仓库中通过git@github.com:megamasha / Vocab-Tester.git(https://github.com/megamasha/Vocab-Tester)访问整个目录。

Mat*_*lia 5

您的process.h,,string.h...来自特定的编译器(watcom),并且包含__declspec不受gcc(通常在Linux上使用的编译器)支持的特定于编译器的关键字(例如)。

string.hctype.h而言,您应该将它们从目录中完全删除,#include并用尖括号(<...>)删除:它们是标准头文件,并且每个编译器都提供其版本(与标准说明兼容)。

使用process.h,情况会有些困难,因为它是非标准的标头。据我所知,process.h似乎只包含一些用于生成进程的函数,并且从快速的外观看,您的应用程序似乎不需要它。如果是这样,只需删除process.h和相对#include。否则,请在评论中告诉我,可能有一个快速的标准(或特定于操作系统,但不特定于编译器)的替代品。