c - make 编译时不链接数学库

标签 c gcc makefile compiler-errors linker-errors

使用 make 编译 xpdf 时出现以下错误。我尝试过使用以下命令:

LIBS=-lm make

但是,它不起作用。我知道问题是 c 编译器无法识别源代码中的数学符号,因为数学库不可用,但我不知道如何修复它。

[ 71%] Linking CXX executable pdftohtml 
    /usr/bin/ld: CMakeFiles/xpdf_objs.dir/Gfx.cc.o: undefined reference to symbol 'acos@@GLIBC_2.2.5'
    //usr/lib64/libm.so.6: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status
    make[2]: *** [xpdf/CMakeFiles/pdftohtml.dir/build.make:219: xpdf/pdftohtml] Error 1
    make[1]: *** [CMakeFiles/Makefile2:428: xpdf/CMakeFiles/pdftohtml.dir/all] Error 2
    make: *** [Makefile:130: all] Error 2

我已经把我的MakefilemakeLists.txt在pastebin上了解更多信息

最佳答案

在阅读 gcc 的手册页后,我意识到我必须使用 g++ 编译器而不是 gcc,其中指出:

The usual way to run GCC is to run the executable called gcc, or machine-gcc when cross-compiling, or machine-gcc-version to run a specific version of GCC. When you compile C++ programs, you should invoke GCC as g++ instead.

关于c - make 编译时不链接数学库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50825735/

相关文章:

c - 在 C 中将断言与数组一起使用

C编程: subscripted value is neither array nor pointer

c - 空的初始值设定项列表是有效的 C 代码吗?

c++ - 使用 Caffe 运行简单的 C++ 程序

c++ - RPath 不适用于从 CMake 生成的 Make Install

c - 从 `setuid` 进程检测父进程死亡

C - strcat 的问题

c - "unix"是 C 中的受限关键字吗?

makefile - 在每个子目录中运行make

linux - 关于 Makefile 的 bash shell