TonyLic TonyLic - 5 months ago 50
Linux Question

32-bit code runs on 64-bit linux machine

My linux is 64 bit Red Hat 6.5. GCC is 4.4.7. I have a code originally running on 32 bit machine, which means, there are a lot of conversion from a pointer to a int. When I make, I get

error: cast from ‘void*’ to ‘int’ loses precision
. I know that is because in 64-bit OS pointer type is 8 bytes.

I don't want to fix all of this one by one because there are too many, so I add
flag in the makefile CFLGAS, which make 32 bit code run on a compiler configured for 64-bit object by default.

Good thing is this compiling error is gone. However, compiler gives me this
main.o: could not read symbols: File in wrong format
. Seems like this is still some compatible issue between 32-bit and 64-bit. Could anyone tell me how to fix this?

This is part of my makefile.common used for gmake:

CFLAGS = -m32 -g -Wall -Wshadow $(INCPATH) $(DEFINES) $(HOST) -DCHANGED
LDFLAGS = -m32

CPP= gcc -E -m32
CC = g++
LD = g++
AS = as --32
S_OFILES = switch.o



$(C_OFILES): %.o:
$(CC) $(CFLAGS) -c $<


You did not enter your linker (g ++) that the assembly code are 32bit instructions.


CPP= gcc -E -m32
CC = g++ -m32
LD = g++ 
AS = as --32