Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ throwing file not recognized: File format not recognized error

Tags:

linux

g++

libpq

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.

like image 229
user1991251 Avatar asked Jan 18 '13 17:01

user1991251


People also ask

What does file is not recognized format error mean?

A "File is Not Recognized Format Error" is produced when attempting to import a drawing file into RAM Concept. The error occurs on some machines when the drawing file is saved on a network drive. The cause of the error is unknown.

What does it mean when Excel says unrecognizable format?

The “Excel file in unrecognizable format error” occurs when the Excel file you are trying to load is corrupted. Microsoft has ensured that the workbook will be recoverable when the file is imported into excel but there are times when the automatic recovery does not happen.

Why can’t I compile an assembly file with GCC?

First, you’re specifying the -S flag, which causes gcc to emit assembly code, rather than object code. Second, you’re missing the -c flag, which tells gcc to compile the file to an object file, but not link it.

Why can’t I link two file types in GCC?

Second, you’re missing the -c flag, which tells gcc to compile the file to an object file, but not link it. If you just remove -S and change nothing else, you’ll end up with an executable program named file1.o and another named file2.o, rather than two object files.


1 Answers

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.

like image 188
Jonathan Wakely Avatar answered Oct 21 '22 22:10

Jonathan Wakely