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

标签 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

我的问题是,正如(我确信)许多人以前遇到过的那样:我只想编译它。

问题 3641178 似乎表明包含文件的顺序很重要,但给出错误的 header 出现在 vt.c 中所有其他包含文件之后。

我尝试在Linux上安装Open Watcom,提供的头文件是相同的。据我所知,这些是标准头文件,我想不出它们为什么会导致编译错误。

如果有人能阐明这一点,我将非常感激。整个目录可以在我的 git 存储库中访问 [email protected] :megamasha/Vocab-Tester.git ( https://github.com/megamasha/Vocab-Tester )

最佳答案

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

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

process.h ,情况有点困难,因为它是一个非标准 header 。不过,据我所知,process.h似乎只包含一些用于生成进程的函数,并且快速浏览一下,您的应用程序似乎不需要它;如果是这样,只需删除 process.h和亲戚#include 。否则,请在评论中告诉我,可能有一个快速标准(或特定于操作系统,但不是特定于编译器)的替换。

关于头文件中的代码似乎会导致编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7114820/

相关文章:

c - int main 无缘无故循环? (PIC编程,XC16,MPLAB)dsPIC33EP

c - 如何在windows 10的sublime text 3中编译运行C程序?

regex - 为什么正则表达式引擎不回溯 .*?

java - 上界通配符(扩展)不起作用;数组列表<? extends SuperType> 不允许子类型的实例

c - 在 OS X 上使用 -m32 编译 union 的冗余大小

C语言检查abc字母表

c++ - 编译错误: invalid conversion when calling base-type constructor

java - Java解释器和编译器规则冲突

linux - 在bash中每n个命令执行一次函数

c - 如何检查分配给进程中打开文件的内存