【解决方案】64位Linux系统下无法编译、运行32位C、C++程序的解决办法

【故障】

1. 从32位系统里面复制过来的32位C或C++程序无法运行,提示找不到程序文件,或找不到libstdc++.so.6库

[oct1158@oct1158-fedora 32env]$ ./test32
bash: ./test32: No such file or directory
[oct1158@oct1158-fedora 32env]$ ./p32
bash: ./p32: No such file or directory
[oct1158@oct1158-fedora 32env]$ ./p32
./p32: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

2. gcc或g++带-m32选项编译成32位的程序,提示失败。例如:

[oct1158@oct1158-fedora 32env]$ gcc test.c -m32
In file included from /usr/include/features.h:452,
                 from /usr/include/bits/libc-header-start.h:33,
                 from /usr/include/stdint.h:26,
                 from /usr/lib/gcc/x86_64-redhat-linux/8/include/stdint.h:9,
                 from test.c:1:
/usr/include/gnu/stubs.h:7:11: fatal error: gnu/stubs-32.h: No such file or directory
 # include <gnu/stubs-32.h>
           ^~~~~~~~~~~~~~~~
compilation terminated.
[oct1158@oct1158-fedora 32env]$ 
[oct1158@oct1158-fedora clocktest]$ g++ p.cpp -m32 -o p
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/8/libstdc++.so when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++

【解决方案】

安装相同版本的i686平台的libgcc和libstdc++。这里所说的相同版本,是指和系统里已有的x86_64平台编译器相同的版本。不相同的版本是不能共存的。

所以,安装前,必须先将已有的64位libgcc和libstdc++升级到最新版本。可以直接升级gcc和gcc-c++:

[oct1158@oct1158-fedora 32env]$ sudo dnf upgrade gcc gcc-c++
[sudo] password for oct1158: 
Last metadata expiration check: 0:32:31 ago on Sun 10 Mar 2019 13:01:22 CST.
Dependencies resolved.
================================================================================
 Package                Arch          Version              Repository      Size
================================================================================
Upgrading:
 cpp                    x86_64        8.3.1-2.fc29         updates         10 M
 gcc                    x86_64        8.3.1-2.fc29         updates         23 M
 gcc-c++                x86_64        8.3.1-2.fc29         updates         12 M
 gcc-gdb-plugin         x86_64        8.3.1-2.fc29         updates        139 k
 libgcc                 x86_64        8.3.1-2.fc29         updates        100 k
 libgomp                x86_64        8.3.1-2.fc29         updates        210 k
 libstdc++              x86_64        8.3.1-2.fc29         updates        460 k
 libstdc++-devel        x86_64        8.3.1-2.fc29         updates        2.1 M

Transaction Summary
================================================================================
Upgrade  8 Packages

Total download size: 48 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): cpp-8.3.1-2.fc29.x86_64.rpm               41 kB/s |  10 MB     04:08    
(2/8): gcc-gdb-plugin-8.3.1-2.fc29.x86_64.rpm    34 kB/s | 139 kB     00:04    
(3/8): libgcc-8.3.1-2.fc29.x86_64.rpm            32 kB/s | 100 kB     00:03    
(4/8): libgomp-8.3.1-2.fc29.x86_64.rpm           33 kB/s | 210 kB     00:06    
(5/8): libstdc++-8.3.1-2.fc29.x86_64.rpm         38 kB/s | 460 kB     00:12    
(6/8): gcc-c++-8.3.1-2.fc29.x86_64.rpm           44 kB/s |  12 MB     04:37    
(7/8): libstdc++-devel-8.3.1-2.fc29.x86_64.rpm   62 kB/s | 2.1 MB     00:34    
(8/8): gcc-8.3.1-2.fc29.x86_64.rpm               49 kB/s |  23 MB     08:00    
--------------------------------------------------------------------------------
Total                                           101 kB/s |  48 MB     08:03     
warning: /var/cache/dnf/updates-0b4cc238d1aa4ffe/packages/cpp-8.3.1-2.fc29.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 429476b4: NOKEY
Fedora 29 - x86_64 - Updates                    1.6 kB/s | 1.6 kB     00:01    
Importing GPG key 0x429476B4:
 Userid     : "Fedora 29 (29) <fedora-29@fedoraproject.org>"
 Fingerprint: 5A03 B4DD 8254 ECA0 2FDA 1637 A20A A56B 4294 76B4
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-29-x86_64
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
Upgrade: libgcc-8.3.1-2.fc29.x86_64
  Upgrading        : libgcc-8.3.1-2.fc29.x86_64                            1/16 
  Running scriptlet: libgcc-8.3.1-2.fc29.x86_64                            1/16 
Upgrade: libgcc-8.3.1-2.fc29.x86_64
Upgrade: libstdc++-8.3.1-2.fc29.x86_64
  Upgrading        : libstdc++-8.3.1-2.fc29.x86_64                         2/16 
  Running scriptlet: libstdc++-8.3.1-2.fc29.x86_64                         2/16 
Upgrade: libstdc++-8.3.1-2.fc29.x86_64
Upgrade: libstdc++-devel-8.3.1-2.fc29.x86_64
  Upgrading        : libstdc++-devel-8.3.1-2.fc29.x86_64                   3/16 
Upgrade: libstdc++-devel-8.3.1-2.fc29.x86_64
Upgrade: libgomp-8.3.1-2.fc29.x86_64
  Upgrading        : libgomp-8.3.1-2.fc29.x86_64                           4/16 
  Running scriptlet: libgomp-8.3.1-2.fc29.x86_64                           4/16 
Upgrade: libgomp-8.3.1-2.fc29.x86_64
Upgrade: cpp-8.3.1-2.fc29.x86_64
  Upgrading        : cpp-8.3.1-2.fc29.x86_64                               5/16 
  Running scriptlet: cpp-8.3.1-2.fc29.x86_64                               5/16 
Upgrade: cpp-8.3.1-2.fc29.x86_64
Upgrade: gcc-8.3.1-2.fc29.x86_64
  Upgrading        : gcc-8.3.1-2.fc29.x86_64                               6/16 
  Running scriptlet: gcc-8.3.1-2.fc29.x86_64                               6/16 
Upgrade: gcc-8.3.1-2.fc29.x86_64
Upgrade: gcc-c++-8.3.1-2.fc29.x86_64
  Upgrading        : gcc-c++-8.3.1-2.fc29.x86_64                           7/16 
Upgrade: gcc-c++-8.3.1-2.fc29.x86_64
Upgrade: gcc-gdb-plugin-8.3.1-2.fc29.x86_64
  Upgrading        : gcc-gdb-plugin-8.3.1-2.fc29.x86_64                    8/16 
  Running scriptlet: gcc-gdb-plugin-8.3.1-2.fc29.x86_64                    8/16 
Upgrade: gcc-gdb-plugin-8.3.1-2.fc29.x86_64
Upgraded: gcc-gdb-plugin-8.2.1-5.fc29.x86_64
  Cleanup          : gcc-gdb-plugin-8.2.1-5.fc29.x86_64                    9/16 
Upgraded: gcc-gdb-plugin-8.2.1-5.fc29.x86_64
  Running scriptlet: gcc-gdb-plugin-8.2.1-5.fc29.x86_64                    9/16 
Upgraded: gcc-c++-8.2.1-5.fc29.x86_64
  Cleanup          : gcc-c++-8.2.1-5.fc29.x86_64                          10/16 
Upgraded: gcc-c++-8.2.1-5.fc29.x86_64
Upgraded: libstdc++-devel-8.2.1-5.fc29.x86_64
  Cleanup          : libstdc++-devel-8.2.1-5.fc29.x86_64                  11/16 
Upgraded: libstdc++-devel-8.2.1-5.fc29.x86_64
Upgraded: gcc-8.2.1-5.fc29.x86_64
  Running scriptlet: gcc-8.2.1-5.fc29.x86_64                              12/16 
  Cleanup          : gcc-8.2.1-5.fc29.x86_64                              12/16 
Upgraded: gcc-8.2.1-5.fc29.x86_64
Upgraded: libstdc++-8.2.1-5.fc29.x86_64
  Cleanup          : libstdc++-8.2.1-5.fc29.x86_64                        13/16 
Upgraded: libstdc++-8.2.1-5.fc29.x86_64
  Running scriptlet: libstdc++-8.2.1-5.fc29.x86_64                        13/16 
Upgraded: libgcc-8.2.1-5.fc29.x86_64
  Cleanup          : libgcc-8.2.1-5.fc29.x86_64                           14/16 
Upgraded: libgcc-8.2.1-5.fc29.x86_64
  Running scriptlet: libgcc-8.2.1-5.fc29.x86_64                           14/16 
Upgraded: cpp-8.2.1-5.fc29.x86_64
  Running scriptlet: cpp-8.2.1-5.fc29.x86_64                              15/16 
  Cleanup          : cpp-8.2.1-5.fc29.x86_64                              15/16 
Upgraded: cpp-8.2.1-5.fc29.x86_64
Upgraded: libgomp-8.2.1-5.fc29.x86_64
  Running scriptlet: libgomp-8.2.1-5.fc29.x86_64                          16/16 
  Cleanup          : libgomp-8.2.1-5.fc29.x86_64                          16/16 
Upgraded: libgomp-8.2.1-5.fc29.x86_64
  Running scriptlet: libgomp-8.2.1-5.fc29.x86_64                          16/16 
  Verifying        : cpp-8.3.1-2.fc29.x86_64                               1/16 
  Verifying        : cpp-8.2.1-5.fc29.x86_64                               2/16 
  Verifying        : gcc-8.3.1-2.fc29.x86_64                               3/16 
  Verifying        : gcc-8.2.1-5.fc29.x86_64                               4/16 
  Verifying        : gcc-c++-8.3.1-2.fc29.x86_64                           5/16 
  Verifying        : gcc-c++-8.2.1-5.fc29.x86_64                           6/16 
  Verifying        : gcc-gdb-plugin-8.3.1-2.fc29.x86_64                    7/16 
  Verifying        : gcc-gdb-plugin-8.2.1-5.fc29.x86_64                    8/16 
  Verifying        : libgcc-8.3.1-2.fc29.x86_64                            9/16 
  Verifying        : libgcc-8.2.1-5.fc29.x86_64                           10/16 
  Verifying        : libgomp-8.3.1-2.fc29.x86_64                          11/16 
  Verifying        : libgomp-8.2.1-5.fc29.x86_64                          12/16 
  Verifying        : libstdc++-8.3.1-2.fc29.x86_64                        13/16 
  Verifying        : libstdc++-8.2.1-5.fc29.x86_64                        14/16 
  Verifying        : libstdc++-devel-8.3.1-2.fc29.x86_64                  15/16 
  Verifying        : libstdc++-devel-8.2.1-5.fc29.x86_64                  16/16 

Upgraded:
  cpp-8.3.1-2.fc29.x86_64             gcc-8.3.1-2.fc29.x86_64                  
  gcc-c++-8.3.1-2.fc29.x86_64         gcc-gdb-plugin-8.3.1-2.fc29.x86_64       
  libgcc-8.3.1-2.fc29.x86_64          libgomp-8.3.1-2.fc29.x86_64              
  libstdc++-8.3.1-2.fc29.x86_64       libstdc++-devel-8.3.1-2.fc29.x86_64      

Complete!
[oct1158@oct1158-fedora 32env]$ 

然后安装glibc.i686:

[oct1158@oct1158-fedora 32env]$ sudo dnf install glibc.i686
[sudo] password for oct1158: 
Last metadata expiration check: 0:46:32 ago on Sun 10 Mar 2019 13:01:22 CST.
Dependencies resolved.
================================================================================
 Package                   Arch         Version             Repository     Size
================================================================================
Installing:
 glibc                     i686         2.28-26.fc29        updates       3.5 M
Upgrading:
 glibc                     x86_64       2.28-26.fc29        updates       3.8 M
 glibc-all-langpacks       x86_64       2.28-26.fc29        updates        25 M
 glibc-common              x86_64       2.28-26.fc29        updates       799 k
 glibc-devel               x86_64       2.28-26.fc29        updates       1.0 M
 glibc-headers             x86_64       2.28-26.fc29        updates       464 k
 glibc-langpack-en         x86_64       2.28-26.fc29        updates       815 k

Transaction Summary
================================================================================
Install  1 Package
Upgrade  6 Packages

Total download size: 36 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): glibc-2.28-26.fc29.x86_64.rpm             43 kB/s | 3.8 MB     01:29    
(2/7): glibc-2.28-26.fc29.i686.rpm               37 kB/s | 3.5 MB     01:37    
(3/7): glibc-common-2.28-26.fc29.x86_64.rpm      26 kB/s | 799 kB     00:30    
(4/7): glibc-devel-2.28-26.fc29.x86_64.rpm       35 kB/s | 1.0 MB     00:29    
(5/7): glibc-headers-2.28-26.fc29.x86_64.rpm     35 kB/s | 464 kB     00:13    
(6/7): glibc-langpack-en-2.28-26.fc29.x86_64.rp  47 kB/s | 815 kB     00:17    
(7/7): glibc-all-langpacks-2.28-26.fc29.x86_64.  58 kB/s |  25 MB     07:27    
--------------------------------------------------------------------------------
Total                                            81 kB/s |  36 MB     07:29     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
Upgrade: glibc-all-langpacks-2.28-26.fc29.x86_64
  Upgrading        : glibc-all-langpacks-2.28-26.fc29.x86_64               1/13 
Upgrade: glibc-all-langpacks-2.28-26.fc29.x86_64
Upgrade: glibc-common-2.28-26.fc29.x86_64
  Upgrading        : glibc-common-2.28-26.fc29.x86_64                      2/13 
Upgrade: glibc-common-2.28-26.fc29.x86_64
Upgrade: glibc-langpack-en-2.28-26.fc29.x86_64
  Upgrading        : glibc-langpack-en-2.28-26.fc29.x86_64                 3/13 
Upgrade: glibc-langpack-en-2.28-26.fc29.x86_64
Upgrade: glibc-2.28-26.fc29.x86_64
  Running scriptlet: glibc-2.28-26.fc29.x86_64                             4/13 
  Upgrading        : glibc-2.28-26.fc29.x86_64                             4/13 
  Running scriptlet: glibc-2.28-26.fc29.x86_64                             4/13 
Upgrade: glibc-2.28-26.fc29.x86_64
Upgrade: glibc-headers-2.28-26.fc29.x86_64
  Running scriptlet: glibc-headers-2.28-26.fc29.x86_64                     5/13 
  Upgrading        : glibc-headers-2.28-26.fc29.x86_64                     5/13 
Upgrade: glibc-headers-2.28-26.fc29.x86_64
Upgrade: glibc-devel-2.28-26.fc29.x86_64
  Upgrading        : glibc-devel-2.28-26.fc29.x86_64                       6/13 
  Running scriptlet: glibc-devel-2.28-26.fc29.x86_64                       6/13 
Upgrade: glibc-devel-2.28-26.fc29.x86_64
Installed: glibc-2.28-26.fc29.i686
  Running scriptlet: glibc-2.28-26.fc29.i686                               7/13 
  Installing       : glibc-2.28-26.fc29.i686                               7/13 
  Running scriptlet: glibc-2.28-26.fc29.i686                               7/13 
Installed: glibc-2.28-26.fc29.i686
Upgraded: glibc-devel-2.28-17.fc29.x86_64
  Running scriptlet: glibc-devel-2.28-17.fc29.x86_64                       8/13 
  Cleanup          : glibc-devel-2.28-17.fc29.x86_64                       8/13 
Upgraded: glibc-devel-2.28-17.fc29.x86_64
Upgraded: glibc-headers-2.28-17.fc29.x86_64
  Cleanup          : glibc-headers-2.28-17.fc29.x86_64                     9/13 
Upgraded: glibc-headers-2.28-17.fc29.x86_64
Upgraded: glibc-all-langpacks-2.28-17.fc29.x86_64
  Cleanup          : glibc-all-langpacks-2.28-17.fc29.x86_64              10/13 
Upgraded: glibc-all-langpacks-2.28-17.fc29.x86_64
  Running scriptlet: glibc-all-langpacks-2.28-17.fc29.x86_64              10/13 
Upgraded: glibc-common-2.28-17.fc29.x86_64
  Cleanup          : glibc-common-2.28-17.fc29.x86_64                     11/13 
Upgraded: glibc-common-2.28-17.fc29.x86_64
Upgraded: glibc-langpack-en-2.28-17.fc29.x86_64
  Cleanup          : glibc-langpack-en-2.28-17.fc29.x86_64                12/13 
Upgraded: glibc-langpack-en-2.28-17.fc29.x86_64
Upgraded: glibc-2.28-17.fc29.x86_64
  Cleanup          : glibc-2.28-17.fc29.x86_64                            13/13 
Upgraded: glibc-2.28-17.fc29.x86_64
  Running scriptlet: glibc-all-langpacks-2.28-26.fc29.x86_64              13/13 
  Running scriptlet: glibc-2.28-17.fc29.x86_64                            13/13 
  Running scriptlet: glibc-common-2.28-26.fc29.x86_64                     13/13 
  Verifying        : glibc-2.28-26.fc29.i686                               1/13 
  Verifying        : glibc-2.28-26.fc29.x86_64                             2/13 
  Verifying        : glibc-2.28-17.fc29.x86_64                             3/13 
  Verifying        : glibc-all-langpacks-2.28-26.fc29.x86_64               4/13 
  Verifying        : glibc-all-langpacks-2.28-17.fc29.x86_64               5/13 
  Verifying        : glibc-common-2.28-26.fc29.x86_64                      6/13 
  Verifying        : glibc-common-2.28-17.fc29.x86_64                      7/13 
  Verifying        : glibc-devel-2.28-26.fc29.x86_64                       8/13 
  Verifying        : glibc-devel-2.28-17.fc29.x86_64                       9/13 
  Verifying        : glibc-headers-2.28-26.fc29.x86_64                    10/13 
  Verifying        : glibc-headers-2.28-17.fc29.x86_64                    11/13 
  Verifying        : glibc-langpack-en-2.28-26.fc29.x86_64                12/13 
  Verifying        : glibc-langpack-en-2.28-17.fc29.x86_64                13/13 

Upgraded:
  glibc-2.28-26.fc29.x86_64           glibc-all-langpacks-2.28-26.fc29.x86_64  
  glibc-common-2.28-26.fc29.x86_64    glibc-devel-2.28-26.fc29.x86_64          
  glibc-headers-2.28-26.fc29.x86_64   glibc-langpack-en-2.28-26.fc29.x86_64    

Installed:
  glibc-2.28-26.fc29.i686                                                       

Complete!
[oct1158@oct1158-fedora 32env]$ 

现在已经可以运行32版本的C程序,但是无法运行32位版本的C++程序,也无法编译32位的C/C++程序。

安装glibc-devel.i686:

[oct1158@oct1158-fedora 32env]$ sudo dnf install glibc-devel.i686
[sudo] password for oct1158: 
Last metadata expiration check: 1:15:38 ago on Sun 10 Mar 2019 13:01:22 CST.
Dependencies resolved.
================================================================================
 Package                Arch          Version              Repository      Size
================================================================================
Installing:
 glibc-devel            i686          2.28-26.fc29         updates        1.0 M
Upgrading:
 libxcrypt              x86_64        4.4.4-1.fc29         updates        119 k
     replacing  libxcrypt-common.noarch 4.2.3-1.fc29
 libxcrypt-devel        x86_64        4.4.4-1.fc29         updates         34 k
Installing dependencies:
 libgcc                 i686          8.3.1-2.fc29         updates        107 k
 libxcrypt              i686          4.4.4-1.fc29         updates        126 k
     replacing  libxcrypt-common.noarch 4.2.3-1.fc29
 libxcrypt-devel        i686          4.4.4-1.fc29         updates         34 k
 whois-nls              noarch        5.4.1-1.fc29         updates         32 k
Installing weak dependencies:
 whois-mkpasswd         x86_64        5.4.1-1.fc29         updates         38 k

Transaction Summary
================================================================================
Install  6 Packages
Upgrade  2 Packages

Total size: 1.5 M
Is this ok [y/N]: y
Downloading Packages:
[SKIPPED] glibc-devel-2.28-26.fc29.i686.rpm: Already downloaded                
[SKIPPED] libgcc-8.3.1-2.fc29.i686.rpm: Already downloaded                     
[SKIPPED] libxcrypt-4.4.4-1.fc29.i686.rpm: Already downloaded                  
[SKIPPED] libxcrypt-devel-4.4.4-1.fc29.i686.rpm: Already downloaded            
[SKIPPED] whois-mkpasswd-5.4.1-1.fc29.x86_64.rpm: Already downloaded           
[SKIPPED] whois-nls-5.4.1-1.fc29.noarch.rpm: Already downloaded                
[SKIPPED] libxcrypt-4.4.4-1.fc29.x86_64.rpm: Already downloaded                
[SKIPPED] libxcrypt-devel-4.4.4-1.fc29.x86_64.rpm: Already downloaded          
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
Installed: whois-nls-5.4.1-1.fc29.noarch
  Installing       : whois-nls-5.4.1-1.fc29.noarch                         1/11 
Installed: whois-nls-5.4.1-1.fc29.noarch
Upgrade: libxcrypt-4.4.4-1.fc29.x86_64
  Upgrading        : libxcrypt-4.4.4-1.fc29.x86_64                         2/11 
Upgrade: libxcrypt-4.4.4-1.fc29.x86_64
Installed: whois-mkpasswd-5.4.1-1.fc29.x86_64
  Installing       : whois-mkpasswd-5.4.1-1.fc29.x86_64                    3/11 
Installed: whois-mkpasswd-5.4.1-1.fc29.x86_64
Installed: libxcrypt-4.4.4-1.fc29.i686
  Installing       : libxcrypt-4.4.4-1.fc29.i686                           4/11 
Installed: libxcrypt-4.4.4-1.fc29.i686
Installed: libgcc-8.3.1-2.fc29.i686
  Installing       : libgcc-8.3.1-2.fc29.i686                              5/11 
  Running scriptlet: libgcc-8.3.1-2.fc29.i686                              5/11 
Installed: libgcc-8.3.1-2.fc29.i686
Installed: libxcrypt-devel-4.4.4-1.fc29.i686
  Installing       : libxcrypt-devel-4.4.4-1.fc29.i686                     6/11 
Installed: libxcrypt-devel-4.4.4-1.fc29.i686
Installed: glibc-devel-2.28-26.fc29.i686
  Installing       : glibc-devel-2.28-26.fc29.i686                         7/11 
  Running scriptlet: glibc-devel-2.28-26.fc29.i686                         7/11 
Installed: glibc-devel-2.28-26.fc29.i686
Upgrade: libxcrypt-devel-4.4.4-1.fc29.x86_64
  Upgrading        : libxcrypt-devel-4.4.4-1.fc29.x86_64                   8/11 
Upgrade: libxcrypt-devel-4.4.4-1.fc29.x86_64
Upgraded: libxcrypt-devel-4.2.3-1.fc29.x86_64
  Cleanup          : libxcrypt-devel-4.2.3-1.fc29.x86_64                   9/11 
Upgraded: libxcrypt-devel-4.2.3-1.fc29.x86_64
Upgraded: libxcrypt-4.2.3-1.fc29.x86_64
  Cleanup          : libxcrypt-4.2.3-1.fc29.x86_64                        10/11 
Upgraded: libxcrypt-4.2.3-1.fc29.x86_64
Obsoleted: libxcrypt-common-4.2.3-1.fc29.noarch
  Obsoleting       : libxcrypt-common-4.2.3-1.fc29.noarch                 11/11 
Obsoleted: libxcrypt-common-4.2.3-1.fc29.noarch
  Running scriptlet: libxcrypt-common-4.2.3-1.fc29.noarch                 11/11 
  Verifying        : glibc-devel-2.28-26.fc29.i686                         1/11 
  Verifying        : libgcc-8.3.1-2.fc29.i686                              2/11 
  Verifying        : libxcrypt-4.4.4-1.fc29.i686                           3/11 
  Verifying        : libxcrypt-common-4.2.3-1.fc29.noarch                  4/11 
  Verifying        : libxcrypt-devel-4.4.4-1.fc29.i686                     5/11 
  Verifying        : whois-mkpasswd-5.4.1-1.fc29.x86_64                    6/11 
  Verifying        : whois-nls-5.4.1-1.fc29.noarch                         7/11 
  Verifying        : libxcrypt-4.4.4-1.fc29.x86_64                         8/11 
  Verifying        : libxcrypt-4.2.3-1.fc29.x86_64                         9/11 
  Verifying        : libxcrypt-devel-4.4.4-1.fc29.x86_64                  10/11 
  Verifying        : libxcrypt-devel-4.2.3-1.fc29.x86_64                  11/11 

Upgraded:
  libxcrypt-4.4.4-1.fc29.x86_64       libxcrypt-devel-4.4.4-1.fc29.x86_64      

Installed:
  glibc-devel-2.28-26.fc29.i686          whois-mkpasswd-5.4.1-1.fc29.x86_64     
  libgcc-8.3.1-2.fc29.i686               libxcrypt-4.4.4-1.fc29.i686            
  libxcrypt-devel-4.4.4-1.fc29.i686      whois-nls-5.4.1-1.fc29.noarch          

Complete!
[oct1158@oct1158-fedora 32env]$

就可以编译32位C程序了。

 

为了编译和运行32位的C++程序,可以安装libstdc++.i686:

[oct1158@oct1158-fedora clocktest]$ sudo dnf install libstdc++.i686
Last metadata expiration check: 0:08:24 ago on Fri 08 Mar 2019 14:01:57 CST.
Dependencies resolved.
================================================================================
 Package            Architecture  Version                Repository        Size
================================================================================
Installing:
 libstdc++          i686          8.3.1-2.fc29           updates          497 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 497 k
Installed size: 1.7 M
Is this ok [y/N]: y
Downloading Packages:
libstdc++-8.3.1-2.fc29.i686.rpm                 254 kB/s | 497 kB     00:01    
--------------------------------------------------------------------------------
Total                                           105 kB/s | 497 kB     00:04     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : libstdc++-8.3.1-2.fc29.i686                            1/1 
  Running scriptlet: libstdc++-8.3.1-2.fc29.i686                            1/1 
  Verifying        : libstdc++-8.3.1-2.fc29.i686                            1/1 

Installed:
  libstdc++-8.3.1-2.fc29.i686                                                   

Complete!
[oct1158@oct1158-fedora clocktest]$ 

可以用下面的命令查看已安装的版本:

[oct1158@oct1158-fedora clocktest]$ sudo dnf install glibc libstdc++
Last metadata expiration check: 0:23:33 ago on Fri 08 Mar 2019 14:01:57 CST.
Package glibc-2.28-26.fc29.x86_64 is already installed.
Package glibc-2.28-26.fc29.i686 is already installed.
Package libstdc++-8.3.1-2.fc29.x86_64 is already installed.
Package libstdc++-8.3.1-2.fc29.i686 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[oct1158@oct1158-fedora clocktest]$ 

32位和64位的版本必须相同才能安装,切记!

 

接下来,编译一个C++程序测试一下:

#include <iostream>

using namespace std;

class A
{
private:
	const char *p;
public:
	A(const char *s);
	void test(void);
};

A::A(const char *s) : p(s)
{
}

void A::test(void)
{
	cout << p << endl;
}

int main(void)
{
	A *a = new A("Hello World!");
	a->test();
	delete a;
	return 0;
}
[oct1158@oct1158-fedora clocktest]$ g++ p.cpp -m32 -o p
[oct1158@oct1158-fedora clocktest]$ ./p
Hello World!
[oct1158@oct1158-fedora clocktest]$ file p
p: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=8cf224918f0a6259f5aea2411ec973a2234a1b02, not stripped
[oct1158@oct1158-fedora clocktest]$ 

这一次编译就成功了

 

[oct1158@oct1158-fedora 4.9.1]$ ./cc1
./cc1: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

找不到libz.so.1的问题也可以用同样的方法解决。

[oct1158@oct1158-fedora 4.9.1]$ sudo dnf upgrade zlib
Last metadata expiration check: 0:04:39 ago on Fri 08 Mar 2019 14:34:16 CST.
Dependencies resolved.
Nothing to do.
Complete!
[oct1158@oct1158-fedora 4.9.1]$ sudo dnf install zlib.i686
Last metadata expiration check: 0:04:52 ago on Fri 08 Mar 2019 14:34:16 CST.
Dependencies resolved.
================================================================================
 Package        Architecture   Version                   Repository        Size
================================================================================
Installing:
 zlib           i686           1.2.11-14.fc29            fedora            91 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 91 k
Installed size: 201 k
Is this ok [y/N]: y
Downloading Packages:
zlib-1.2.11-14.fc29.i686.rpm                     65 kB/s |  91 kB     00:01    
--------------------------------------------------------------------------------
Total                                            23 kB/s |  91 kB     00:03     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : zlib-1.2.11-14.fc29.i686                               1/1 
  Running scriptlet: zlib-1.2.11-14.fc29.i686                               1/1 
  Verifying        : zlib-1.2.11-14.fc29.i686                               1/1 

Installed:
  zlib-1.2.11-14.fc29.i686                                                      

Complete!
[oct1158@oct1158-fedora 4.9.1]$ ./cc1

^C
[oct1158@oct1158-fedora 4.9.1]$ 

装了zlib.i686就可以运行了cc1程序了。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

巨大八爪鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值