问题描述
我试图编译在Linux上,我知道编译在OSX一些code,但我得到的一些问题。
所有的文件有一个名为.H头,并且所有的文件都在同一目录下。我编译如下:
GCC的* .c -std = C99 -lpthread
虽然这code并在OSX编译,我得到了一堆奇怪的链接错误在我的Ubuntu的安装。我错过了几个编译选项?这是一个默认的Ubuntu的服务器附加软件包安装 GCC
和建立必要的
安装。
在文件从errorLogger.h包含0,
从configParser.h:17,
从configParser.c:9:
signalHandling.h:24:18:错误:未知类型名称'sigset_t
configParser.c:在函数'parseConfigFile:
configParser.c:114:5:警告:函数'函数getline'[-Wimplicit函数声明]的隐式声明
24:在文件从errorLogger.h包含0,
从global.h:18,
从connection.h:19,
从connection.c:10:
signalHandling.h:24:18:错误:未知类型名称'sigset_t
connection.c:在函数'createConnectionQueue:
connection.c:189:28:警告:赋值时将指针整数,未作施放[默认启用]
24:在文件从errorLogger.h包含0,
从database.h:16,
从database.c:9:
signalHandling.h:24:18:错误:未知类型名称'sigset_t
24:在文件从errorLogger.h包含0,
从errorLogger.c:10:
signalHandling.h:24:18:错误:未知类型名称'sigset_t
errorLogger.c:在功能reportError:
errorLogger.c:63:5:警告:函数'strerror_r'隐式声明[-Wimplicit功能声明]
errorLogger.c:在功能的LogMessage:
errorLogger.c:87:5:警示:功能则localtime_r'隐式声明[-Wimplicit功能声明]
errorLogger.c:在函数'processErrorQueue:
errorLogger.c:131:17:警告:隐函数声明开放[-Wimplicit函数声明]
errorLogger.c:131:57:错误:'O_APPEND'未申报(在一次使用此功能)
errorLogger.c:131:57:注:每个未声明的标识符为它出现在每个函数报道只有一次
errorLogger.c:131:68:错误:'O_CREAT'未申报(在一次使用此功能)
errorLogger.c:131:78:错误:'O_WRONLY'未申报(第一次使用此功能使用)
errorLogger.c:131:88:错误:'S_IWRITE'未申报(在一次使用此功能)
errorLogger.c:131:99:错误:'S_IREAD'未申报(在一次使用此功能)
errorLogger.c:146:13:警告:函数'的fsync'的隐式声明[-Wimplicit功能声明]
errorLogger.c:在函数'startErrorLogger:
errorLogger.c:167:36:错误:'O_APPEND'未申报(在一次使用此功能)
errorLogger.c:167:47:错误:'O_CREAT'未申报(在一次使用此功能)
errorLogger.c:167:57:错误:'O_WRONLY'未申报(第一次使用此功能使用)
errorLogger.c:167:67:错误:'S_IWRITE'未申报(在一次使用此功能)
errorLogger.c:167:78:错误:'S_IREAD'未申报(在一次使用此功能)
errorLogger.c:214:57:错误:'O_EXCL'未申报(在一次使用此功能)
errorLogger.c:231:27:警告:赋值时将指针整数,未作施放[默认启用]
errorLogger.c:在函数'closeErrorLogger:
errorLogger.c:246:9:警告:函数'pthread_kill'的隐式声明[-Wimplicit功能声明]
24:在文件从errorLogger.h包含0,
从global.h:18,
从global.c:9:
signalHandling.h:24:18:错误:未知类型名称'sigset_t
23:0文件从main.c中包括:
signalHandling.h:24:18:错误:未知类型名称'sigset_t
main.c中:在函数'主':
main.c中:53:5:警告:函数隐式声明blockSignals[-Wimplicit函数声明]
main.c中:61:45:错误:'sizeof的无效应用不完全型'结构addrinfo中的
main.c中:62:29:错误:'sizeof的无效应用不完全型'结构addrinfo中的
main.c中:64:10:错误:提领指向不完全类型
main.c中:65:10:错误:提领指向不完全类型
main.c中:66:10:错误:提领指向不完全类型
main.c中:66:23:错误:'AI_PASSIVE'未申报(第一次使用此功能使用)
main.c中:66:23:注:每个未声明的标识符为它出现在每个函数报道只有一次
main.c中:69:5:警告:函数隐式声明的getaddrinfo'[-Wimplicit函数声明]
main.c中:73:9:警告:函数'gai_strerror'隐式声明[-Wimplicit功能声明]
main.c中:73:9:警告:格式'%s'的预期类型的char *'的说法,但论据4的类型'诠释'[-Wformat]
main.c中:73:9:警告:格式'%s'的预期类型的char *'的说法,但论据4的类型'诠释'[-Wformat]
main.c中:81:41:错误:提领指向不完全类型
main.c中:83:30:错误:提领指向不完全类型
main.c中:83:46:错误:提领指向不完全类型
main.c中:83:64:错误:提领指向不完全类型
main.c中:96:30:错误:提领指向不完全类型
main.c中:96:44:错误:提领指向不完全类型
main.c中:112:5:警告:函数'freeaddrinfo'的隐式声明[-Wimplicit功能声明]
main.c中:138:9:错误:未知类型名称'FD_SET
main.c中:142:9:警告:函数'FD_ZERO'隐式声明[-Wimplicit功能声明]
main.c中:143:9:警告:函数'FD_SET'隐式声明[-Wimplicit功能声明]
main.c中:145:9:警告:函数'PSELECT'隐式声明[-Wimplicit功能声明]
10:0文件从signalHandling.c包括:
signalHandling.h:24:18:错误:未知类型名称'sigset_t
signalHandling.c:12:18:错误:未知类型名称'sigset_t
signalHandling.c:在函数'setHandler:
signalHandling.c:51:53:错误:'sizeof的不完全型'结构sigaction的无效的应用
signalHandling.c:52:36:错误:'sizeof的不完全型'结构sigaction的无效的应用
signalHandling.c:54:5:警告:函数'sigemptyset'隐式声明[-Wimplicit功能声明]
signalHandling.c:54:30:错误:提领指向不完全类型
signalHandling.c:60:9:警告:函数'sigaddset'隐式声明[-Wimplicit功能声明]
signalHandling.c:60:35:错误:提领指向不完全类型
signalHandling.c:67:17:错误:提领指向不完全类型
signalHandling.c:72:9:警告:函数'的sigaction'隐式声明[-Wimplicit功能声明]
你可能缺少这些带来了隐含在OS X上的一些的#include
S,但不是在Linux操作系统。
从错误信息来看,你可能缺少包括至少:
-
<&signal.h中GT;
(为sigset_t
和其它) -
< fcntl.h>
(为0 _ *
) -
<&unistd.h中GT;
(用于一堆东西) -
<&netdb.h中GT;
(各种网络功能和常数) -
<&stdio.h中GT;
(为函数getline
)
您可能还需要定义一些功能的宏(例如, _POSIX_C_SOURCE
),以获得一定的依赖于系统的功能,包括 strerror_r
和 PSELECT
。
I am trying to compile some code on linux that I KNOW compiles on OSX, but I am getting some issues.
All of the files have headers named .h, and all of the files are in the same directory. I am compiling like this:
gcc *.c -std=c99 -lpthread
And while this code does compile on OSX, I get a bunch of weird linker errors on my Ubuntu install. Am I missing a few compiler options? It is a default Ubuntu-server install with the additional packages gcc
and build-essential
installed.
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]
You are probably missing some #include
s which are brought in implicitly on OS X, but not on Linux.
Judging from the error messages, you are probably missing includes for at least:
<signal.h>
(forsigset_t
and others)<fcntl.h>
(forO_*
)<unistd.h>
(for a bunch of stuff)<netdb.h>
(for various network functions and constants)<stdio.h>
(forgetline
)
You may also need to define some feature macros (e.g, _POSIX_C_SOURCE
) to get certain system-dependent functions, including strerror_r
and pselect
.
这篇关于C $ C $的C编译错误在Linux上(同code编译在OSX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!