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.
- $ sudo apt-get install build-essential module-assistant
- $ 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