GCC生成链接问题

GCC Make Link Issue

本文关键字:问题 链接 GCC      更新时间:2023-10-16

我正试图在HTR工具Utils上执行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

Makefile:

#
# 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

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

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