libgccも入れないと

やっとコンパイルできると思ったら、以下のエラー。

$ cc -m32 -g -Wall -o sample32 sample32.c -lsqlite3
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: ld はステータス 1 で終了しました
$

覚えたてのwhatprovidesで検索してみるけど32bit版も入っているっぽいぞ。

$ yum whatprovides */libgcc_s.so
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
gcc-4.4.7-4.el6.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)
Repo        : base
Matched from:
Filename    : /usr/lib/gcc/x86_64-redhat-linux/4.4.4/32/libgcc_s.so
Filename    : /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so



compat-gcc-34-3.4.6-19.el6.x86_64 : Compatibility GNU Compiler Collection
Repo        : base
Matched from:
Filename    : /usr/lib/gcc/x86_64-redhat-linux/3.4.6/libgcc_s.so



gcc-4.4.7-3.el6.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)
Repo        : installed
Matched from:
Filename    : /usr/lib/gcc/x86_64-redhat-linux/4.4.4/32/libgcc_s.so
Filename    : /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so



$

とりあえず、gcc関連のパッケージはなにがあるのかを見てみる。

$ yum list | grep gcc
gcc.x86_64                               4.4.7-3.el6                    @base   
gcc-c++.x86_64                           4.4.7-3.el6                    @base   
gcc-gfortran.x86_64                      4.4.7-3.el6                    @base   
libgcc.x86_64                            4.4.7-3.el6                    @base   
compat-gcc-34.x86_64                     3.4.6-19.el6                   base    
compat-gcc-34-c++.x86_64                 3.4.6-19.el6                   base    
compat-gcc-34-g77.x86_64                 3.4.6-19.el6                   base    
gcc.x86_64                               4.4.7-4.el6                    base    
gcc-c++.x86_64                           4.4.7-4.el6                    base    
gcc-gfortran.x86_64                      4.4.7-4.el6                    base    
gcc-gnat.x86_64                          4.4.7-4.el6                    base    
gcc-java.x86_64                          4.4.7-4.el6                    base    
gcc-objc.x86_64                          4.4.7-4.el6                    base    
gcc-objc++.x86_64                        4.4.7-4.el6                    base    
libgcc.i686                              4.4.7-4.el6                    base    
libgcc.x86_64                            4.4.7-4.el6                    base    
mingw32-gcc.x86_64                       4.4.6-4.el6                    base    
mingw32-gcc-c++.x86_64                   4.4.6-4.el6                    base    
mingw32-gcc-gfortran.x86_64              4.4.6-4.el6                    base    
mingw32-gcc-objc.x86_64                  4.4.6-4.el6                    base    
mingw32-gcc-objc++.x86_64                4.4.6-4.el6                    base    
$ yum list | grep libgcc
libgcc.x86_64                            4.4.7-3.el6                    @base   
libgcc.i686                              4.4.7-4.el6                    base    
libgcc.x86_64                            4.4.7-4.el6                    base    
$ rpm -qa | grep libgcc
libgcc-4.4.7-3.el6.x86_64
$ rpm -ql libgcc
/lib64/libgcc_s-4.4.7-20120601.so.1
/lib64/libgcc_s.so.1
/usr/share/doc/libgcc-4.4.7
/usr/share/doc/libgcc-4.4.7/COPYING.LIB
$

libgcc.i686がないからかも。ということでインストールしてみた。

$ su
パスワード:
# yum install libgcc.i686
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.nus.edu.sg
 * updates: mirror.nus.edu.sg
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package libgcc.i686 0:4.4.7-4.el6 will be installed
--> Finished Dependency Resolution
Error:  Multilib version problems found. This often means that the root
       cause is something else and multilib version checking is just
       pointing out that there is a problem. Eg.:
       
         1. You have an upgrade for libgcc which is missing some
            dependency that another package requires. Yum is trying to
            solve this by installing an older version of libgcc of the
            different architecture. If you exclude the bad architecture
            yum will tell you what the root cause is (which package
            requires what). You can try redoing the upgrade with
            --exclude libgcc.otherarch ... this should give you an error
            message showing the root cause of the problem.
       
         2. You have multiple architectures of libgcc installed, but
            yum can only see an upgrade for one of those arcitectures.
            If you don't want/need both architectures anymore then you
            can remove the one with the missing update and everything
            will work.
       
         3. You have duplicate versions of libgcc installed already.
            You can use "yum check" to get yum show these errors.
       
       ...you can also use --setopt=protected_multilib=false to remove
       this checking, however this is almost never the correct thing to
       do as something else is very likely to go wrong (often causing
       much more problems).
       
       Protected multilib versions: libgcc-4.4.7-4.el6.i686 != libgcc-4.4.7-3.el6.x86_64
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
# rpm -qa | grep gcc
gcc-gfortran-4.4.7-3.el6.x86_64
gcc-c++-4.4.7-3.el6.x86_64
libgcc-4.4.7-3.el6.x86_64
gcc-4.4.7-3.el6.x86_64
#

バージョンが違う(4.4.7-4を入れようとしているのにすでにインストールされている64bitは4.4.7-3となっている)のでインストールできない。つまりアップデートが必要してからlibgcc.i686をインストールする必要あり。

# yum update gcc
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.nus.edu.sg
 * updates: mirror.nus.edu.sg
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.4.7-3.el6 will be updated
--> Processing Dependency: gcc = 4.4.7-3.el6 for package: gcc-gfortran-4.4.7-3.el6.x86_64
--> Processing Dependency: gcc = 4.4.7-3.el6 for package: gcc-c++-4.4.7-3.el6.x86_64
---> Package gcc.x86_64 0:4.4.7-4.el6 will be an update
--> Processing Dependency: libgomp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64
--> Processing Dependency: cpp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64
--> Processing Dependency: libgcc >= 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64
--> Running transaction check
---> Package cpp.x86_64 0:4.4.7-3.el6 will be updated
---> Package cpp.x86_64 0:4.4.7-4.el6 will be an update
---> Package gcc-c++.x86_64 0:4.4.7-3.el6 will be updated
---> Package gcc-c++.x86_64 0:4.4.7-4.el6 will be an update
--> Processing Dependency: libstdc++-devel = 4.4.7-4.el6 for package: gcc-c++-4.4.7-4.el6.x86_64
--> Processing Dependency: libstdc++ = 4.4.7-4.el6 for package: gcc-c++-4.4.7-4.el6.x86_64
---> Package gcc-gfortran.x86_64 0:4.4.7-3.el6 will be updated
---> Package gcc-gfortran.x86_64 0:4.4.7-4.el6 will be an update
--> Processing Dependency: libgfortran = 4.4.7-4.el6 for package: gcc-gfortran-4.4.7-4.el6.x86_64
---> Package libgcc.x86_64 0:4.4.7-3.el6 will be updated
---> Package libgcc.x86_64 0:4.4.7-4.el6 will be an update
---> Package libgomp.x86_64 0:4.4.7-3.el6 will be updated
---> Package libgomp.x86_64 0:4.4.7-4.el6 will be an update
--> Running transaction check
---> Package libgfortran.x86_64 0:4.4.7-3.el6 will be updated
---> Package libgfortran.x86_64 0:4.4.7-4.el6 will be an update
---> Package libstdc++.x86_64 0:4.4.7-3.el6 will be updated
---> Package libstdc++.x86_64 0:4.4.7-4.el6 will be an update
---> Package libstdc++-devel.x86_64 0:4.4.7-3.el6 will be updated
---> Package libstdc++-devel.x86_64 0:4.4.7-4.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                 Arch           Version              Repository    Size
================================================================================
Updating:
 gcc                     x86_64         4.4.7-4.el6          base          10 M
Updating for dependencies:
 cpp                     x86_64         4.4.7-4.el6          base         3.7 M
 gcc-c++                 x86_64         4.4.7-4.el6          base         4.7 M
 gcc-gfortran            x86_64         4.4.7-4.el6          base         4.7 M
 libgcc                  x86_64         4.4.7-4.el6          base         101 k
 libgfortran             x86_64         4.4.7-4.el6          base         265 k
 libgomp                 x86_64         4.4.7-4.el6          base         118 k
 libstdc++               x86_64         4.4.7-4.el6          base         293 k
 libstdc++-devel         x86_64         4.4.7-4.el6          base         1.6 M

Transaction Summary
================================================================================
Upgrade       9 Package(s)

Total download size: 26 M
Is this ok [y/N]: y
Downloading Packages:
(1/9): cpp-4.4.7-4.el6.x86_64.rpm                        | 3.7 MB     00:03     
(2/9): gcc-4.4.7-4.el6.x86_64.rpm                        |  10 MB     00:04     
(3/9): gcc-c++-4.4.7-4.el6.x86_64.rpm                    | 4.7 MB     00:01     
(4/9): gcc-gfortran-4.4.7-4.el6.x86_64.rpm               | 4.7 MB     00:02     
(5/9): libgcc-4.4.7-4.el6.x86_64.rpm                     | 101 kB     00:00     
(6/9): libgfortran-4.4.7-4.el6.x86_64.rpm                | 265 kB     00:00     
(7/9): libgomp-4.4.7-4.el6.x86_64.rpm                    | 118 kB     00:00     
(8/9): libstdc++-4.4.7-4.el6.x86_64.rpm                  | 293 kB     00:00     
(9/9): libstdc++-devel-4.4.7-4.el6.x86_64.rpm            | 1.6 MB     00:00     
--------------------------------------------------------------------------------
Total                                           1.1 MB/s |  26 MB     00:23     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : libgcc-4.4.7-4.el6.x86_64                                   1/18 
  Updating   : libstdc++-4.4.7-4.el6.x86_64                                2/18 
  Updating   : libstdc++-devel-4.4.7-4.el6.x86_64                          3/18 
  Updating   : libgfortran-4.4.7-4.el6.x86_64                              4/18 
  Updating   : libgomp-4.4.7-4.el6.x86_64                                  5/18 
  Updating   : cpp-4.4.7-4.el6.x86_64                                      6/18 
  Updating   : gcc-4.4.7-4.el6.x86_64                                      7/18 
  Updating   : gcc-gfortran-4.4.7-4.el6.x86_64                             8/18 
  Updating   : gcc-c++-4.4.7-4.el6.x86_64                                  9/18 
  Cleanup    : gcc-c++-4.4.7-3.el6.x86_64                                 10/18 
  Cleanup    : gcc-gfortran-4.4.7-3.el6.x86_64                            11/18 
  Cleanup    : libstdc++-devel-4.4.7-3.el6.x86_64                         12/18 
  Cleanup    : gcc-4.4.7-3.el6.x86_64                                     13/18 
  Cleanup    : libstdc++-4.4.7-3.el6.x86_64                               14/18 
  Cleanup    : libgcc-4.4.7-3.el6.x86_64                                  15/18 
  Cleanup    : cpp-4.4.7-3.el6.x86_64                                     16/18 
  Cleanup    : libgomp-4.4.7-3.el6.x86_64                                 17/18 
  Cleanup    : libgfortran-4.4.7-3.el6.x86_64                             18/18 
  Verifying  : libstdc++-devel-4.4.7-4.el6.x86_64                          1/18 
  Verifying  : gcc-gfortran-4.4.7-4.el6.x86_64                             2/18 
  Verifying  : cpp-4.4.7-4.el6.x86_64                                      3/18 
  Verifying  : libgomp-4.4.7-4.el6.x86_64                                  4/18 
  Verifying  : libgcc-4.4.7-4.el6.x86_64                                   5/18 
  Verifying  : gcc-4.4.7-4.el6.x86_64                                      6/18 
  Verifying  : libgfortran-4.4.7-4.el6.x86_64                              7/18 
  Verifying  : gcc-c++-4.4.7-4.el6.x86_64                                  8/18 
  Verifying  : libstdc++-4.4.7-4.el6.x86_64                                9/18 
  Verifying  : gcc-c++-4.4.7-3.el6.x86_64                                 10/18 
  Verifying  : libgfortran-4.4.7-3.el6.x86_64                             11/18 
  Verifying  : gcc-4.4.7-3.el6.x86_64                                     12/18 
  Verifying  : libgomp-4.4.7-3.el6.x86_64                                 13/18 
  Verifying  : libgcc-4.4.7-3.el6.x86_64                                  14/18 
  Verifying  : cpp-4.4.7-3.el6.x86_64                                     15/18 
  Verifying  : gcc-gfortran-4.4.7-3.el6.x86_64                            16/18 
  Verifying  : libstdc++-devel-4.4.7-3.el6.x86_64                         17/18 
  Verifying  : libstdc++-4.4.7-3.el6.x86_64                               18/18 

Updated:
  gcc.x86_64 0:4.4.7-4.el6                                                      

Dependency Updated:
  cpp.x86_64 0:4.4.7-4.el6              gcc-c++.x86_64 0:4.4.7-4.el6            
  gcc-gfortran.x86_64 0:4.4.7-4.el6     libgcc.x86_64 0:4.4.7-4.el6             
  libgfortran.x86_64 0:4.4.7-4.el6      libgomp.x86_64 0:4.4.7-4.el6            
  libstdc++.x86_64 0:4.4.7-4.el6        libstdc++-devel.x86_64 0:4.4.7-4.el6    

Complete!
# yum install libgcc.i686
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.nus.edu.sg
 * updates: mirror.nus.edu.sg
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package libgcc.i686 0:4.4.7-4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch            Version                Repository       Size
================================================================================
Installing:
 libgcc            i686            4.4.7-4.el6            base            112 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 112 k
Installed size: 144 k
Is this ok [y/N]: y
Downloading Packages:
libgcc-4.4.7-4.el6.i686.rpm                              | 112 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : libgcc-4.4.7-4.el6.i686                                      1/1 
  Verifying  : libgcc-4.4.7-4.el6.i686                                      1/1 

Installed:
  libgcc.i686 0:4.4.7-4.el6                                                     

Complete!
#

やっとコンパイル成功

めでたくコンパイル成功しました。

$ cc -m32 -g -Wall -o sample32 sample32.c -lsqlite3
$ ldd sample32
	linux-gate.so.1 =>  (0x00aab000)
	libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x00b8c000)
	libc.so.6 => /lib/libc.so.6 (0x0017a000)
	libdl.so.2 => /lib/libdl.so.2 (0x00ae5000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00325000)
	/lib/ld-linux.so.2 (0x00902000)
$