简体   繁体   English

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

[英]Code in header files seems to cause errors on compile

I have a CLI program consisting of a single vt.c file that compiles and runs under Windows (cmd.exe) using Open Watcom. 我有一个CLI程序,该程序由一个vt.c文件组成,该文件可以使用Open Watcom在Windows(cmd.exe)下编译并运行。 I can also compile it for Linux while running Open Watcom on Windows (and the resulting build runs under linux). 我还可以在Windows上运行Open Watcom时为Linux编译它(并且生成的版本在Linux下运行)。

When I try to compile it under linux however (using make, which calls cc), I get 375 lines of error messages. 但是,当我尝试在linux下编译它时(使用make,它调用cc),我收到375行错误消息。 Here are some of them, where many subsequent errors were similar, I have only pasted the first few: 以下是其中一些,其中许多后续错误类似,我只粘贴了前几个:

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

My problem is, as (I'm sure) many have had before: I just want it to compile. 我的问题是,正如(我确定)许多人以前遇到的那样:我只希望它可以编译。

Question 3641178 seems to suggest that the order of the include files is important, but the headers that are giving errors come AFTER all other included files in vt.c. 问题3641178似乎暗示了包含文件的顺序很重要,但是出现错误的标头出现在vt.c中的所有其他包含文件之后。

I have tried installing Open Watcom on Linux, and the provided header files are the same. 我尝试在Linux上安装Open Watcom,并且提供的头文件相同。 As far as I know, these are standard header files, and I can think of no reason why they should cause compile errors. 据我所知,这些是标准头文件,我无法认为它们会引起编译错误。

If anyone can shed any light on this, I'd be very grateful. 如果有人能对此有所启示,我将不胜感激。 The entire directory can be accessed in my git repo at git@github.com:megamasha/Vocab-Tester.git ( https://github.com/megamasha/Vocab-Tester ) 可以在我的git仓库中通过git@github.com:megamasha / Vocab-Tester.git( https://github.com/megamasha/Vocab-Tester )访问整个目录

Your process.h , string.h , ... come from a specific compiler (watcom) and contain compiler-specific keywords (eg __declspec ) that are not supported by gcc (the compiler usually used on Linux). 您的process.hstring.h ,...来自特定的编译器(watcom),并且包含gcc (通常在Linux上使用的编译器)不支持的特定于编译器的关键字(例如__declspec )。

As far as string.h and ctype.h are concerned, you should remove them completely from your directory and #include them with angular brackets ( <...> ): they are standard headers and each compiler provide its versions (that are compatible with what the standard says). string.hctype.h而言,您应该将它们从目录中完全删除,并用尖括号( <...>#include它们:它们是标准头文件,并且每个编译器都提供其版本(兼容符合标准规定)。

With process.h , the situation is a bit more difficult, since it's a nonstandard header. 使用process.h ,情况有点困难,因为它是非标准头文件。 Still, as far as I see, process.h seems to contain just some functions that are used to spawn processes, and, from a quick look, it seems that your application doesn't need it; 就我所知, process.h似乎只包含一些用于生成进程的函数,并且从快速的外观看,您的应用程序似乎不需要它。 if so, just remove process.h and the relative #include . 如果是这样,只需删除process.h和相对的#include Otherwise, tell me in the comment, probably there's a quick standard (or OS-specific, but not compiler-specific) replacement. 否则,请在评论中告诉我,可能有一个快速的标准(或特定于操作系统,但不特定于编译器)的替代品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM