7

getting following error with the command g++ -o test -L . -l pq

libpq.so: file not recognized: File format not recognized

#file libpq.so
libpq.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped

gcc version 4.1.2 20070115 (SUSE Linux)

I am getting the same error if I try to use -l dbodbc instead of -l pq.

Note that test.c is a simple hello world program.

Thanks in Advance.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
user1991251
  • 81
  • 1
  • 1
  • 3
  • I bet you're trying to compile this with a 32-bit version of G++. –  Jan 18 '13 at 17:36
  • which g++ shows "/usr/bin/g++" and file on /usr/bin/g++ shows "/usr/bin/g++: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), stripped". So I think this makes it clear that g++ is 64 bit – user1991251 Jan 18 '13 at 17:53
  • Don't call your program `test` it is the name of a shell builtin. And what does the commands `file`, `nm -D`, and `objdump -x` say about your `libpq.so` ? – Basile Starynkevitch Jan 18 '13 at 18:33
  • file libpq.so libpq.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped – user1991251 Jan 18 '13 at 18:43
  • objdump -x libpq.so objdump: libpq.so: File format not recognized – user1991251 Jan 18 '13 at 18:43
  • objdump is throwing this error only in one particular linux box. If I copy the same .so to a different box, objdump is showing correct info. The issue is with machine or the compiler version? – user1991251 Jan 19 '13 at 13:44

1 Answers1

7

file /usr/bin/g++ tells you that g++ itself is a 64-bit executable, i.e. it runs on a 64-bit machine, it doesn't tell you that g++ can compile 64-bit code (it's very unlikely but it could be a cross compiler for a completely different processor!) Use g++ -v or g++ -dumpmachine to find out what target it generates executables for.

G++ doesn't actually use that library, it just passes the -l option to the linker, so the error is coming from the linker, ld

If ld and objdump are both saying they can't recognize the library but the same file is fine on a different machine, I would try updating or reinstalling the binutils package, which provides both ld and objdump.

You might have a 32-bit binutils installed, so its ld and objdump wouldn't understand the x86_64 library. Ensure you have the 64-bit (i.e. x86_64) binutils RPM installed.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521