【问题标题】:how to use "make and building executables" in Linux work [duplicate]如何在 Linux 工作中使用“制作和构建可执行文件”[重复]
【发布时间】:2017-01-30 12:39:57
【问题描述】:

我尝试在我的 c 源代码上使用 make 并创建了可执行文件。但可执行文件没有完成预期的任务。即使当我尝试单独编译.c文件时make文件编译并生成了可执行文件,它也给出了许多未定义的引用问题 错误是

/tmp/cc4tx0BG.o: In function `main':
cubist.c:(.text+0xdc): undefined reference to `Of'
cubist.c:(.text+0xe7): undefined reference to `Of'
cubist.c:(.text+0xfa): undefined reference to `Of'
cubist.c:(.text+0x10f): undefined reference to `KRInit'
cubist.c:(.text+0x114): undefined reference to `ExecTime'
cubist.c:(.text+0x127): undefined reference to `PrintHeader'
cubist.c:(.text+0x139): undefined reference to `Of'
[...]
cubist.c:(.text+0xb79): undefined reference to `MaxAtt'
cubist.c:(.text+0xb83): undefined reference to `InitialiseEnvData'
cubist.c:(.text+0xb8a): undefined reference to `XVAL'
cubist.c:(.text+0xb93): undefined reference to `CrossVal'
cubist.c:(.text+0xb9a): undefined reference to `SingleCttee'
cubist.c:(.text+0xb9f): undefined reference to `ExecTime'
cubist.c:(.text+0xbab): undefined reference to `Of'
collect2: error: ld returned 1 exit status

拜托,任何人都可以告诉如何在 Linux 中使用 make 和构建可执行文件。

【问题讨论】:

  • 减少输出,从前 10 行开始就可以理解了。
  • 我认为这是一个链接错误。你是如何编译你的源代码的?
  • 我使用 gcc 编译器来获取名为 cubist 的可执行文件。 gcc -o cubist cubist.c
  • @melaku 您使用的工具链是标准的还是定制的?您能否也发布您的来源 cubist.c - 我们可能会更好地帮助您。
  • 是标准工具链。 Cubist 的 GPL 版本 c 源代码可在 (rulequest.com/download.html) 获得。你也可以看到cubist.c

标签: c linux compiler-errors executable gnu-make


【解决方案1】:

认为(不确定)您是说您使用 Make 成功生成了可执行文件(至少我是这样解释“在我的 c 源代码上使用 make 并创建可执行文件”的方式)——如果我错了,请纠正我!)。如果是这种情况,请像这样调用 make:make -B --trace,您将看到用于构建可执行文件的确切命令,然后您希望知道在尝试构建时错过了哪些编译器/链接器标志或库手动的东西。

【讨论】:

    猜你喜欢
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    相关资源
    最近更新 更多