在linux c编译出错,Linux上C代码的编译错误(在OSX上编译相同的代码)

我想在linux上编译一些我知道在OSX上编译的代码,但是我遇到了一些问题.

所有文件都有名为.h的头文件,所有文件都在同一目录下.我这样编译:

gcc *.c -std=c99 -lpthread

虽然这段代码在OSX上编译,但我在Ubuntu安装上遇到了一堆奇怪的链接器错误.我错过了一些编译器选项吗?这是一个默认的Ubuntu服务器安装,安装了附加软件包gcc和build-essential.

In file included from errorLogger.h:24:0,

from configParser.h:17,

from configParser.c:9:

signalHandling.h:24:18: error: unknown type name ‘sigset_t’

configParser.c: In function ‘parseConfigFile’:

configParser.c:114:5: warning: implicit declaration of function ‘getline’ [-Wimplicit-function-declaration]

In file included from errorLogger.h:24:0,

from global.h:18,

from connection.h:19,

from connection.c:10:

signalHandling.h:24:18: error: unknown type name ‘sigset_t’

connection.c: In function ‘createConnectionQueue’:

connection.c:189:28: warning: assignment makes integer from pointer without a cast [enabled by default]

In file included from errorLogger.h:24:0,

from database.h:16,

from database.c:9:

signalHandling.h:24:18: error: unknown type name ‘sigset_t’

In file included from errorLogger.h:24:0,

from errorLogger.c:10:

signalHandling.h:24:18: error: unknown type name ‘sigset_t’

errorLogger.c: In function ‘reportError’:

errorLogger.c:63:5: warning: implicit declaration of function ‘strerror_r’ [-Wimplicit-function-declaration]

errorLogger.c: In function ‘logMessage’:

errorLogger.c:87:5: warning: implicit declaration of function ‘localtime_r’ [-Wimplicit-function-declaration]

errorLogger.c: In function ‘processErrorQueue’:

errorLogger.c:131:17: warning: implicit declaration of function ‘open’ [-Wimplicit-function-declaration]

errorLogger.c:131:57: error: ‘O_APPEND’ undeclared (first use in this function)

errorLogger.c:131:57: note: each undeclared identifier is reported only once for each function it appears in

errorLogger.c:131:68: error: ‘O_CREAT’ undeclared (first use in this function)

errorLogger.c:131:78: error: ‘O_WRONLY’ undeclared (first use in this function)

errorLogger.c:131:88: error: ‘S_IWRITE’ undeclared (first use in this function)

errorLogger.c:131:99: error: ‘S_IREAD’ undeclared (first use in this function)

errorLogger.c:146:13: warning: implicit declaration of function ‘fsync’ [-Wimplicit-function-declaration]

errorLogger.c: In function ‘startErrorLogger’:

errorLogger.c:167:36: error: ‘O_APPEND’ undeclared (first use in this function)

errorLogger.c:167:47: error: ‘O_CREAT’ undeclared (first use in this function)

errorLogger.c:167:57: error: ‘O_WRONLY’ undeclared (first use in this function)

errorLogger.c:167:67: error: ‘S_IWRITE’ undeclared (first use in this function)

errorLogger.c:167:78: error: ‘S_IREAD’ undeclared (first use in this function)

errorLogger.c:214:57: error: ‘O_EXCL’ undeclared (first use in this function)

errorLogger.c:231:27: warning: assignment makes integer from pointer without a cast [enabled by default]

errorLogger.c: In function ‘closeErrorLogger’:

errorLogger.c:246:9: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]

In file included from errorLogger.h:24:0,

from global.h:18,

from global.c:9:

signalHandling.h:24:18: error: unknown type name ‘sigset_t’

In file included from main.c:23:0:

signalHandling.h:24:18: error: unknown type name ‘sigset_t’

main.c: In function ‘main’:

main.c:53:5: warning: implicit declaration of function ‘blockSignals’ [-Wimplicit-function-declaration]

main.c:61:45: error: invalid application of ‘sizeof’ to incomplete type ‘struct addrinfo’

main.c:62:29: error: invalid application of ‘sizeof’ to incomplete type ‘struct addrinfo’

main.c:64:10: error: dereferencing pointer to incomplete type

main.c:65:10: error: dereferencing pointer to incomplete type

main.c:66:10: error: dereferencing pointer to incomplete type

main.c:66:23: error: ‘AI_PASSIVE’ undeclared (first use in this function)

main.c:66:23: note: each undeclared identifier is reported only once for each function it appears in

main.c:69:5: warning: implicit declaration of function ‘getaddrinfo’ [-Wimplicit-function-declaration]

main.c:73:9: warning: implicit declaration of function ‘gai_strerror’ [-Wimplicit-function-declaration]

main.c:73:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat]

main.c:73:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat]

main.c:81:41: error: dereferencing pointer to incomplete type

main.c:83:30: error: dereferencing pointer to incomplete type

main.c:83:46: error: dereferencing pointer to incomplete type

main.c:83:64: error: dereferencing pointer to incomplete type

main.c:96:30: error: dereferencing pointer to incomplete type

main.c:96:44: error: dereferencing pointer to incomplete type

main.c:112:5: warning: implicit declaration of function ‘freeaddrinfo’ [-Wimplicit-function-declaration]

main.c:138:9: error: unknown type name ‘fd_set’

main.c:142:9: warning: implicit declaration of function ‘FD_ZERO’ [-Wimplicit-function-declaration]

main.c:143:9: warning: implicit declaration of function ‘FD_SET’ [-Wimplicit-function-declaration]

main.c:145:9: warning: implicit declaration of function ‘pselect’ [-Wimplicit-function-declaration]

In file included from signalHandling.c:10:0:

signalHandling.h:24:18: error: unknown type name ‘sigset_t’

signalHandling.c:12:18: error: unknown type name ‘sigset_t’

signalHandling.c: In function ‘setHandler’:

signalHandling.c:51:53: error: invalid application of ‘sizeof’ to incomplete type ‘struct sigaction’

signalHandling.c:52:36: error: invalid application of ‘sizeof’ to incomplete type ‘struct sigaction’

signalHandling.c:54:5: warning: implicit declaration of function ‘sigemptyset’ [-Wimplicit-function-declaration]

signalHandling.c:54:30: error: dereferencing pointer to incomplete type

signalHandling.c:60:9: warning: implicit declaration of function ‘sigaddset’ [-Wimplicit-function-declaration]

signalHandling.c:60:35: error: dereferencing pointer to incomplete type

signalHandling.c:67:17: error: dereferencing pointer to incomplete type

signalHandling.c:72:9: warning: implicit declaration of function ‘sigaction’ [-Wimplicit-function-declaration]

解决方法:

您可能遗漏了一些#includes,它们是在OS X上隐式引入的,但在Linux上却没有.

从错误消息判断,您可能至少缺少包括:

>< signal.h> (对于sigset_t和其他人)

>< fcntl.h> (对于O_ *)

>< unistd.h> (对于一堆东西)

>< netdb.h> (用于各种网络功能和常量)

>< stdio.h> (对于getline)

您可能还需要定义一些特征宏(例如,_POSIX_C_SOURCE)以获取某些依赖于系统的函数,包括strerror_r和pselect.

标签:ubuntu,c-3,linux,gcc,linker

来源: https://codeday.me/bug/20190712/1442130.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值