0

I get the following error while compiling xpdf using make. I've tried using the command:

LIBS=-lm make

However, it doesn't work. I know the problem is that the c compiler cannot recognise the math symbols in the source code because the math library is not available to it, but I don't know how to fix it.

[ 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

I have put my Makefile and makeLists.txt on pastebin for more information

bit
  • 443
  • 1
  • 7
  • 19
  • 2
    What's `-l make`? The compiler should have passed `-lm` to link the math library – Eugene Sh. Jun 12 '18 at 21:00
  • 1
    Possible [duplicate question](https://stackoverflow.com/questions/16344445/undefined-reference-to-pow-even-with-math-h-and-the-library-link-lm) may be others are better. – Weather Vane Jun 12 '18 at 21:03
  • @Eugene Sh, apologies. I've now corrected it to `-lm`. @Weather Vane It's not a duplicate, I've read several posts and tried their answers but none of them worked for me. – bit Jun 12 '18 at 21:12
  • @weather: xpdf is written in C++ and there is no need to link C++ programs against `-lm`; it is supposed to be automatic. – rici Jun 12 '18 at 21:25
  • @rici thank you, I did say other previous Qs could be better. Any suggestions? – Weather Vane Jun 12 '18 at 21:44
  • @weather i can't find a better q and i'm in a cafe w/o a laptop. To me it feels like a glibc version mismatch where some DSO was compiled against an old glibc. (2.2.5? Rly?) – rici Jun 12 '18 at 21:48
  • @rici. I used gcc as the compiler rather than g++. Maybe thats why `-lm` wasn't linked automatically – bit Jun 13 '18 at 08:40
  • 1
    @mywrath: yes, if you are linking a c++ project, you should use g++ to get the right link options. – rici Jun 13 '18 at 12:27

1 Answers1

0

I realised I had to use the g++ compiler instead of gcc after reading the man page for gcc which stated:

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.

bit
  • 443
  • 1
  • 7
  • 19