Installed a UBUNTU16 64-bit system to compile 64-bit and 32-bit programs with GCC in this environment
The default 64-bit environment is already installed in GCC
1. First confirm that the installed environment is not 64-bit
[Email protected]:~/desktop$ dpkg--print-architecture The following output is represented as 64-bit AMD64
2. Verify that the system supports multi-architecture environments
[Email protected]:~/desktop$ dpkg--print-foreign-architectures The following output represents a 32-bit supported architecture i386
If not supported then manually open, as follows
sudo dpkg--add-architecture i386sudo apt-get updatesudo apt-get Dist-upgrade
3. Install the GCC library that supports the 32 compilation program
sudo apt-get install Gcc-multilib g++-multilib
4. Compile a test program main.c the following
int Main (int argc,char *argv[]) { if (argc! =2 ) {printf ( " please input one argv\n " return 0 ; } printf ( " argc=%d, argv[1]=%s\n Span style= "COLOR: #800000" > ", Argc,argv[1 return 0 ;}
5. Compile the 64-bit, 32-bit executable program separately, MAIN64,MAIN32
[Email protected]:~/desktop$ gcc-o main32-m32 main.c [email protected]:
6. Use the file command to view the compiled program schema.
[Email protected]:~/desktop$ file Main64 main64:elf --bit LSB executable, x86- -, version1(SYSV), dynamically linked, interpreter/lib64/ld-linux-x86- -. So.2, forGnu/linux2.6. +, buildid[sha1]=f8573379cf22e444381d36eec08862e69a90ae4d, not stripped[email protected]:~/desktop$ file Main32 main32:elf +-bit LSB executable, Intel80386, version1(SYSV), dynamically linked, interpreter/lib/ld-linux.so.2, forGnu/linux2.6. +, buildid[sha1]=cbff7c2ddf45b505ffd1e60adce482c0cc896475, not stripped
7. Run the compiled 64-bit, 32-bit test program
[email protected]:~/desktop$./main64 THIS64ARGC=2 , argv[1]= this64[email protected]: ~/desktop$./main32 THIS32ARGC=2 , argv[1]=this32
Reference: https://www.cnblogs.com/mliudong/p/4086797.html
UBUNTU16 64-bit compiled 64-bit programs and 32-bit programs