What is the difference between 32-bit gcc and 64-bit gcc with the -m32 option?

My team recently worked on JNI, so we ran into various problems regarding 32-bit and 64-bit architectures. Take an example ( temp.c ).

 #include <stdio.h> void main(){ printf("long=%d\n",sizeof(long)); } 

Is there a difference between gcc_32_bit temp.c and gcc_64_bit -m32 temp.c ?

Verified cases:

Case-1: compiled on 64-bit ubuntu using gcc temp.c Conclusion: long=8 on 64-bit ubuntu.

Case-2: compiled on 64-bit ubuntu using gcc -m32 temp.c Conclusion: long=4 on 64-bit ubuntu.

Code-3: compiled on a 64-bit MAC address (a 64-bit cross-compiler is used ) using /usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-gcc temp.c . Conclusion: long=8 on 64-bit ubuntu.

Code 4: compiled on a 64-bit MAC ( 32-bit cross-compiler used ) using /usr/local/gcc-4.8.1-for-linux32/bin/i586-pc-linux-gcc temp.c Conclusion: Error: cannot run on 64-bit ubuntu.

We use the MAC cross compiler because we do not have a 32-bit Linux machine.

+5
source share
1 answer

It may seem a little strange, but it started working nowhere.

Like amdn posted in the comments above, this could be due to the lack of a library for 32-bit. Since it did not work before, I installed gcc-multilib and some automatic updates of Ubuntu, and it started working.

Thank you all for your great help.

0
source

Source: https://habr.com/ru/post/1267119/


All Articles