c++ - GCC 建立链接问题

标签 c++ gcc makefile

我正在尝试在 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

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

最佳答案

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

关于c++ - GCC 建立链接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34063989/

相关文章:

在 Ubuntu 17.10 上升级 CUDA-9.1 后预测包安装期间出现 R 错误

python - 从父目录导入子目录模块时出现 Sphinx ImportError

c++ - mmap() 两次返回相同的指针

c - __libc_start_main 和 _start 是什么?

c - 如何自动生成C源文件

makefile - 如何在目录列表中应用通配符

c++ - 什么是 ATOMIC_FLAG_INIT 以及它应该如何使用?

c++ - 使用带有 qi::grammar 的 boost::spirit::qi::phrase_parse() 时出错

c++ - 为什么是 'int x = + "foo";'类型错误但不是语法错误?

c++ - C++ 中的静态变量