【问题标题】:Error when compiling C program that has multiple header files [duplicate]编译具有多个头文件的 C 程序时出错 [重复]
【发布时间】:2017-05-15 12:08:43
【问题描述】:

我有 kmeans_seq.cbikmeans_seq.c 文件。文件bikmeans_seq.c 包括两个标题:kmeans_seq.hbikmeans_seq.h。当我使用 gcc bikmeans_seq.c -o bikmeans 编译 bikmeans_seq.c 时,我收到此错误:

Undefined symbols for architecture x86_64:
  "_euclidean_dist", referenced from:
      _points_assignment in bikmeans_seq-5c462b.o
      _partition_clusters in bikmeans_seq-5c462b.o
      _standard_deviation in bikmeans_seq-5c462b.o
  "_find_max", referenced from:
      _standard_deviation in bikmeans_seq-5c462b.o
  "_kmeans", referenced from:
      _main in bikmeans_seq-5c462b.o
      _partition_clusters in bikmeans_seq-5c462b.o
     (maybe you meant: _bisecting_kmeans)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我不确定这个错误是什么。有人可以提示我为什么会收到此错误吗?谢谢。

【问题讨论】:

标签: c compiler-errors linker clang


【解决方案1】:

没有来源有点困难,但试试这个:

gcc -Wall bikmeans_seq.c kmeans_seq.c -o bikmeans

即使这样可行,我还是建议使用 makefile。

希望这会有所帮助!

【讨论】:

  • 我认为OP正在使用clang,根据clang: error: linker command failed with exit code 1 (use -v to see invocation)显示的这一行输出
  • @Toby 在问题中他写道“当我使用 gcc bikmeans_seq.c -o bikmeans 编译 bikmeans_seq.c 时出现此错误”,但我也有同样的疑问
  • 必须是苹果系统。当他们从 gcc 迁移到 clang 时,他们把事情彻底搞砸了,但是将 gcc 链接到 clang。 80% 的 Apple 用户现在认为他们使用 gcc。
猜你喜欢
  • 2011-08-25
  • 1970-01-01
  • 2011-07-07
  • 2011-02-03
  • 1970-01-01
  • 2018-11-28
  • 1970-01-01
  • 1970-01-01
  • 2010-10-13
相关资源
最近更新 更多