首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >编译器在C程序中抛出“未定义符号”错误

编译器在C程序中抛出“未定义符号”错误
EN

Stack Overflow用户
提问于 2014-11-12 06:22:50
回答 2查看 3.9K关注 0票数 2

我在test.c中有以下内容

代码语言:javascript
运行
复制
#include <stdio.h>
#include "stdfn.h"

int main(void)
{
    printOut(10, "Hello, world!\n");
    //bash("say hello world");
}

资料来源:https://github.com/KrasnayaSecurity/HydroCarbon

当我试图编译时,我会得到这个错误:

代码语言:javascript
运行
复制
President-JohnHEden:HydroCarbon aleksandr$ gcc test.c -o test -Wall
Undefined symbols for architecture x86_64:
  "_printOut", referenced from:
      _main in test-134873.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-12 06:26:05

在这里,您的链接器无法找到printOut()函数的定义。

您已经通过嵌入printOut()在您的test.c文件中包含了stdfn.h声明,但是test.c中没有该函数的定义。该定义存在于stdfn.c中。因此,您需要将两个文件合并在一起才能生成二进制文件。

将编译行更改为

代码语言:javascript
运行
复制
gcc test.c stdfn.c -o test -Wall
票数 0
EN

Stack Overflow用户

发布于 2014-11-12 06:52:32

你可以做一个

代码语言:javascript
运行
复制
gcc test.c stdfn.c -o test -Wall 

(假定stdfn.c是printOut()的定义所在),以便将包含用户定义函数的文件链接到当前使用它的文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26880575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档