【问题标题】:GCC Make Link IssueGCC 建立链接问题
【发布时间】:2015-12-03 10:49:28
【问题描述】:

我正在尝试在 HTR-toolsUtils 上执行 make 并且遇到以下问题:

gcc -g -Wall -lm  -I./include -o pgmmedian pgmmedian.c libpgm.o
Undefined symbols for architecture x86_64:
  "_CALC_MEDIAN", referenced from:
      _main in pgmmedian-7918de.o
  "_MERGE_SLICE", referenced from:
      _main in pgmmedian-7918de.o
  "_SORT_SLICE", referenced from:
      _main in pgmmedian-7918de.o
  "_pgm_getuint", referenced from:
      _pgm_readpgminitrest in libpgm.o
      _pgm_readpgmrow in libpgm.o
  "_pgm_writepgmrowplain", referenced from:
      _pgm_writepgmrow in libpgm.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pgmmedian] Error 1

生成文件:

#
# CONFIGURABLE OPTIONS
#

#CC =           cc
CC =            gcc

#CFLAGS =       -O3 -I.
CFLAGS =        -g
WFLAGS =        -Wall
LDFLAGS =       -lm
#LDFLAGS =       -s

BINARIESDIR =        $(HOME)/bin
SCRIPTSDIR  =        $(HOME)/scripts
EXAMPLESDIR =        $(HOME)/CATTI-Examples

... 

我在 OSX El Captain 上运行。我读了一些建议使用 g++ 而不是 gcc 运行的问题,但没有运气

使用 gcc -lstdc++ 我得到相同的错误,使用 g++(通过在 Makefile 中更改它们)我得到:

clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
pgmskew.c:24:10: fatal error: 'values.h' file not found
#include <values.h>
         ^
1 error generated.
make: *** [pgmskew] Error 1

➜ gcc -v

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

有什么建议吗?提前致谢 。

【问题讨论】:

  • 您已标记此问题c++ 但您正在编译一个 C 文件,对吗?此外,您使用 GCC,您使用的是 Apple 的假 GCC,即 Clang。这与 GCC 无关。
  • “我读了一些建议使用 g++ 而不是 gcc 运行的问题,但没有运气” 我认为这些问题是关于完全不同的错误,那么你为什么认为那会这里合适吗?

标签: c++ gcc makefile


【解决方案1】:

您缺少一些定义这些符号的库。您需要找出libpgm.o 需要什么库并链接到它。

【讨论】:

    猜你喜欢
    • 2010-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 2012-01-12
    • 1970-01-01
    • 2018-08-02
    相关资源
    最近更新 更多