How does GCC on ubuntu 64 compile 32-bit programs

Run command

gcc -v

display:

Target: x86_64-linux-gnu

So, my gcc generates 64-bit programs by default.

If you want to compile a 32-bit program, you must add the -m32 option. But I tried it and it still didn't work.

 

It turned out that something needed to be installed.

 

  1. $ sudo apt-get install build-essential module-assistant  
  2. $ sudo apt-get install gcc-multilib g++-multilib  

 

 

After it's installed, it's OK.

such as:

gcc -m32 hello.c

 

If the following error occurs during compilation:

.//libupdate.so: undefined reference to `operator delete(void*)'
.//libupdate.so: undefined reference to `operator new(unsigned int)'
.//libupdate.so: undefined reference to `__cxa_pure_virtual'
.//libupdate.so: undefined reference to `operator delete[](void*)'
.//libupdate.so: undefined reference to `operator new[](unsigned int)'
.//libupdate.so: undefined reference to `__gxx_personality_v0'
.//libupdate.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
.//libupdate.so: undefined reference to `pow'
.//libupdate.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: error: ld returned 1 exit status
 

You can use g ++ instead, or add the option: -lstdc ++

 

Reprinted at: https://www.cnblogs.com/longintchar/p/5224400.html

Published 54 original articles · Like 89 · Visit 680,000+

Guess you like

Origin blog.csdn.net/ayang1986/article/details/105405592