C 代码在 Linux 上编译错误(相同代码在 OSX 上编译)

2024-03-31

我正在尝试在 Linux 上编译一些我知道可以在 OSX 上编译的代码,但我遇到了一些问题。

所有文件都有名为 .h 的标头,并且所有文件都位于同一目录中。我是这样编译的:

gcc *.c -std=c99 -lpthread

虽然这段代码确实可以在 OSX 上编译,但我在安装 Ubuntu 时遇到了一堆奇怪的链接器错误。我是否缺少一些编译器选项?这是带有附加软件包的默认 Ubuntu 服务器安装gcc and 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]

你可能错过了一些#include在 OS X 上隐式引入,但在 Linux 上则不然。

从错误消息来看,您可能至少缺少以下内容:

  • <signal.h> (for sigset_t和别的)
  • <fcntl.h> (for O_*)
  • <unistd.h>(对于一堆东西)
  • <netdb.h>(对于各种网络函数和常量)
  • <stdio.h> (for getline)

您可能还需要定义一些功能宏(例如,_POSIX_C_SOURCE)以获得某些与系统相关的功能,包括strerror_r and pselect.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C 代码在 Linux 上编译错误(相同代码在 OSX 上编译) 的相关文章

  • VS 程序在调试模式下崩溃,但在发布模式下不崩溃?

    我正在 VS 2012 中运行以下程序来尝试 Thrust 函数查找 include cuda runtime h include device launch parameters h include
  • 与 Qt 项目的静态链接

    我有一个在 Visual Studio 2010 Professional 中构建的 Qt 项目 但是 当我运行它 在调试或发布模式下 时 它会要求一些 Qt dll 如果我提供 dll 并将它们放入 System32 中 它就可以工作 但
  • 如何在 SqlDataReader.Read() 期间从死锁异常中恢复

    我的 NET 应用程序的事件日志显示 它在从 Sql Server 读取数据时偶尔会出现死锁 这种情况通常非常罕见 因为我们已经优化了查询以避免死锁 但有时仍然会发生 过去 我们在调用ExecuteReader函数在我们的SqlComman
  • 类的成员复制

    在学习 复制成员 概念时 书中给出了如下说法 此外 如果非静态成员是引用 const 或没有复制赋值的用户定义类型 则无法生成默认赋值 我不太明白这个声明到底想传达什么 或者说这个说法指的是哪一种场景 谢谢 该语句与编译器自动为您编写的类
  • 从 WebBrowser 控件 C# 获取滚动值

    我试图在 WebBrowser 控件中获取网页的 Y 滚动索引 但无法访问内置滚动条的值 有任何想法吗 对于标准模式下的 IE 使用文档类型 正如你所说 scrollTop是的财产元素 而不是 HtmlDocument htmlDoc th
  • 如何在服务器端按钮点击时关闭当前标签页?

    我尝试在确认后关闭当前选项卡 因此我将以下代码放在确认按钮的末尾 但选项卡没有关闭 string jScript ClientScript RegisterClientScriptBlock this GetType keyClientBl
  • 无法在内存位置找到异常源:cudaError_enum

    我正在尝试确定 Microsoft C 异常的来源 test fft exe 中 0x770ab9bc 处的第一次机会异常 Microsoft C 异常 内存位置 0x016cf234 处的 cudaError enum 我的构建环境是 I
  • 如何通过 JsonConvert.DeserializeObject 在动态 JSON 中使用 null 条件运算符

    我正在使用 Newtonsoft 反序列化已知的 JSON 对象并从中检索一些值 如果存在 关键在于对象结构可能会不断变化 因此我使用动态来遍历结构并检索值 由于对象结构不断变化 我使用 null 条件运算符来遍历 JSON 代码看起来像这
  • 是否有相当于 Clang/LLVM 的 .spec 文件,在哪里可以找到参考?

    The gcc驱动程序可以配置为使用特定的链接器 特定的选项和其他细节 例如覆盖系统头 specs files 当前 截至撰写本文时 GCC 版本 4 9 0 的手册此处描述了规范文件 https gcc gnu org onlinedoc
  • ASP.NET MailMessage.BodyEncoding 和 MailMessage.SubjectEncoding 默认值

    很简单的问题 但我在 MSDN 上找不到答案 查找 ASP NET 将用于的默认值 MailMessage BodyEncoding and MailMessage SubjectEncoding 如果你不在代码中设置它们 Thanks F
  • C# 中的 strstr() 等效项

    我有两个byte 我想找到第二个的第一次出现byte 在第一个byte 或其中的一个范围 我不想使用字符串来提高效率 翻译第一个byte to a string会效率低下 基本上我相信就是这样strstr 在 C 中做 最好的方法是什么 这
  • 如何更改 Ubuntu 14.04 上的 php-cli 版本?

    我是 Linux 新手 在篡改时破坏了一些 php 设置 如果我执行一个包含以下内容的 php 脚本 phpinfo 它显示 php 版本为 5 6 但通过命令行 如果我运行php v它返回 7 0 版本 我想让两个版本匹配 我怎样才能修复
  • cout 和字符串连接

    我刚刚复习了我的 C 我尝试这样做 include
  • 跨多个域的 ASP.NET 会话

    是否有合适的 NET 解决方案来在多个域上提供持久服务器会话 即 如果该网站的用户在 www site1 com 下登录 他们也将在 www site2 com 下登录 安全是我们正在开发的程序的一个问题 Thanks 它是否需要在会话中
  • 使用taskkill停止Windows服务

    我需要帮助来使用 C 终止 Windows 服务 现在要终止该服务 请使用以下选项 从命令 sc queryex ServiceName 发现后PID服务的 taskkill pid 1234 exemple f 为了便于阅读 但如果您明白
  • 您是否将信息添加到每个 .hpp/.cpp 文件的顶部? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 创建新的 C 头文件 源文件时 您会在顶部添加哪些信息 例如 您是否添加日期 您的姓名 文件描述等 您是否使用结构化格式来存储此信息 e g F
  • 如何在 DropDownList 中保留空格 - ASP.net MVC Razor 视图

    我在视图中通过以下方式绑定我的模型 问题是我的项目文本是格式化文本 单词之间有空格 如下所示 123 First 234 00 123 AnotherItem 234 00 123 Second 234 00 我想保留此项目文本中的空格 即
  • 矩阵到数组 C#

    这将是转换方阵的最有效方法 例如 1 2 3 4 5 6 7 8 9 into 1 2 3 4 5 6 7 8 9 in c 我在做 int array2D new int 1 2 3 4 5 6 7 8 9 int array1D new
  • 将 char[][] 转换为 char** 会导致段错误吗?

    好吧 我的 C 有点生疏了 但我想我应该用 C 来做我的下一个 小 项目 这样我就可以对其进行抛光 并且我已经有不到 20 行的段错误了 这是我的完整代码 define ROWS 4 define COLS 4 char main map
  • 使我的 COM 程序集调用异步

    我刚刚 赢得 了在当前工作中维护用 C 编码的遗留库的特权 这个dll 公开使用 Uniface 构建的大型遗留系统的方法 除了调用 COM 对象之外别无选择 充当此遗留系统与另一个系统的 API 之间的链接 在某些情况下 使用 WinFo

随机推荐

  • 如何限制谁可以在 github 存储库上合并为 master?

    我在我的 Github 存储库上进行了设置 主分支检查 激活 以下内容的分支保护规则 合并前需要审查请求请求 所需批准审稿人 1 包括管理员 限制谁可以推送到匹配的分支 然后我面临的情况是 团队中至少有一个人必须批准 PR 然后有人才能将自
  • 将Python源代码拆分到单独的目录中?

    以下是我的公司 foo com 使用的一些各种 Python 包 com foo bar web com foo bar lib com foo zig web com foo zig lib com foo zig lib lib1 co
  • 在函数内用 $ 索引数据框?

    许多 R 教科书鼓励使用 从 data frames 检索变量 列 但是 我发现这在函数内部不起作用 我不明白为什么 data BOD print BOD These work BOD demand BOD demand This work
  • 以特定格式将数据存储在txt文件中

    我的问题与我之前的问题相关 如何以特定格式显示txt文件中的数据 https stackoverflow com questions 731917 how to display data from txt file in specific
  • jQuery UI 选项卡禁用选项卡导航

    我尝试使用禁用选项卡导航 var tabs tabs tabs select function event ui return false 但是 这也会禁用我用于导航的流链接 input nexttab click function var
  • Form.ShowDialog() 并处置

    如果我有这样的方法 public void Show Form1 f new Form1 f ShowDialog 我还需要调用 dispose 吗即使它将超出范围 也将符合垃圾回收的条件 从一些测试来看 多次调用此 Show 在某些时候
  • Chrome 84 中缩小后的图像模糊

    最近一次 Google Chrome 更新后 我网站上的 Retina 图像变得模糊 它们仍然是视网膜图像 当我在新选项卡中打开图像时 它是双倍尺寸的图像 但由于某种原因 它们看起来模糊就像非视网膜图像一样 因此 图像的缩小算法似乎有问题
  • 从 R 中的 Facet_wrap ggplot2 中删除一个级别/组

    我的 tbl df gt str p2p dt SKILL A Classes tbl dt tbl data table and data frame 693 obs of 35 variables Patch Factor w 7 le
  • 使用 C# 中的 asp.net 表单登录屏幕抓取网站?

    是否可以为受表单登录保护的网站编写屏幕抓取程序 当然 我可以访问该网站 但我不知道如何登录该网站并在 C 中保存我的凭据 此外 任何 C 屏幕截图的好例子将不胜感激 这已经完成了吗 这很简单 您需要自定义登录 HttpPost 方法 你可以
  • Angular CLI 中未显示字体精美的图标:8.2.2 而是显示正方形

    我已经安装了 Font Awesome 通过npm install save font awesome angular font awesome from https www npmjs com package angular font a
  • Kotlin 中按多个字段对集合进行排序[重复]

    这个问题在这里已经有答案了 假设我有一个人员列表 我需要先按年龄排序 然后按姓名排序 来自 C 背景的我可以通过使用 LINQ 轻松地用所述语言实现此目的 var list new List
  • 使用“AsParallel()”/“Parallel.ForEach()”指南?

    寻求一些关于利用杠杆的建议AsParallel or Parallel ForEach 以加快速度 请参阅下面我得到的方法 此示例的简化 粗制化 它需要一个类似 美国 法国 亚太地区 的列表 其中 亚太地区 可能是其他 50 个 美国 法国
  • Python 版本识别错误

    我已经开始使用 pyqtdeploy 来使用 pyqt 并制作跨平台应用程序 不幸的是 当我实际尝试启动它时 我收到错误 启动器中的致命错误 无法使用 C Python34 python exe C Python34 pyqtdeploy
  • objectify-appengine - 嵌入式类 - 不是受支持的属性类型

    我正在谷歌应用程序引擎上尝试objectify 版本2 2 3 嵌入类示例 wiki 我收到此错误 java lang IllegalArgumentException one com mypkg LevelOne is not a sup
  • YUI 圆形输入框

    是否可以使用 YUI 将我的所有输入框更改为圆角 我无法使用背景图像 因为输入的宽度是可变的 并且我无法添加围绕它们的 div 因为生成了一些输入元素 另外 我不能使用边框半径或任何 moz webkit 变体 因为它需要在 IE6 中显示
  • 如何使用 DataStax Java 驱动程序设置 Cassandra 客户端到节点加密?

    我已在 Cassandra 集群上设置了节点到节点加密 现在我想设置客户端到节点 根据本文档 http www datastax com documentation cassandra 2 0 cassandra security secu
  • Android 6.0 未经许可捕获图像

    我需要让用户使用 Android 6 0 拍照 从图库或相机应用程序 因为我不需要控制相机 所以我想使用此处描述的意图 但是 如果您不需要此类控制 则可以仅使用 ACTION IMAGE CAPTURE 意图来请求图像 当您启动意图时 系统
  • 在 watir 中自动下载文件

    如何一键点击链接自动从浏览器下载 Excel 文件 而无需通过 watir 中的 另存为 和其他窗口 我试图保持它独立于操作系统 所以对使用 win32ole gem 不感兴趣 为了这个任务 我调整了我的个人资料偏好 我的代码如下所示 镀铬
  • 如何防止 Axios 对我的请求参数进行编码?

    我正在尝试通过 GET 请求中的 URL 参数传入 API 密钥 但是 我注意到 Axios 在发送请求时对我的 API 密钥中的字符进行编码 这会导致 API 拒绝我的请求 因为它无法识别我的密钥 如何防止 Axios 对我的 GET 参
  • C 代码在 Linux 上编译错误(相同代码在 OSX 上编译)

    我正在尝试在 Linux 上编译一些我知道可以在 OSX 上编译的代码 但我遇到了一些问题 所有文件都有名为 h 的标头 并且所有文件都位于同一目录中 我是这样编译的 gcc c std c99 lpthread 虽然这段代码确实可以在 O