Did you delete the library before recompiling with the 64-bit build?
Your compilation sequence worked for me:
$ g++ -m64 -Wall -c prog.cpp $ g++ -m64 -Wall -c test1.cpp $ ar -cvq libtest.a test1.o a - test1.o $ g++ -m64 -Wall -o prog1 prog.o libtest.a $ file test1.o prog.o test1.o: ELF 64-bit LSB relocatable, AMD x86-64, version 1 (SYSV), not stripped prog.o: ELF 64-bit LSB relocatable, AMD x86-64, version 1 (SYSV), not stripped $ ./prog1 Valx=5 $
When I compiled a 32-bit file:
$ g++ -m32 -Wall -c prog.cpp $ g++ -m32 -Wall -c test1.cpp $ file test1.o prog.o test1.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped prog.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped $ ar -cvq libtest.a test1.o a - test1.o $ g++ -m32 -Wall -o prog1 prog.o libtest.a /usr/bin/ld: warning: i386:x86-64 architecture of input file `libtest.a(test1.o)' is incompatible with i386 output $ file prog1 prog1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped $ ./prog1 Memory fault $
These are several RHEL 5 releases (not all of them are current):
Linux toru 2.6.18-128.el5
My GCC is version 4.1.2. My version of AR is next, and RANLIB prints the same version:
GNU ar 2.17.50.0.6-9.el5 20061020
I did not need to use ranlib directly.