Results 1 to 6 of 6
I'm trying to compile a 32bit elf on an intel 64bit system. I'm using -m32 and g++ is very unhelpfully linking to the wrong library path. It should look in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-20-2013 #1Just Joined!
- Join Date
- Aug 2010
- Posts
- 31
g++ -m32 not working.
I'm trying to compile a 32bit elf on an intel 64bit system. I'm using -m32 and g++ is very unhelpfully linking to the wrong library path. It should look in /usr/lib/gcc/i686-linux-gnu/, not /usr/lib/gcc/x86_64-linux-gnu/
And what exactly is the difference between /usr/lib/gcc/i686-linux-gnu/ and /usr/lib32 ?
The direcotry /usr/lib/gcc/x86_64-linux-gnu/ has an empty folder and a symlink, and nothing else whatsoever.
list of packages I have installed:Code:caibbor@helios ~ $ g++ -m32 -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.2-2ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
Code:caibbor@helios ~ $ dpkg -l '*g++*' Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-==========================================-==========================-==========================-========================================================================================== ii g++ 4:4.7.2-1ubuntu2 amd64 GNU C++ compiler ii g++-4.6 4.6.3-10ubuntu1 amd64 GNU C++ compiler un g++-4.6-multilib <none> (no description available) ii g++-4.7 4.7.2-2ubuntu1 amd64 GNU C++ compiler ii g++-4.7-multilib 4.7.2-2ubuntu1 amd64 GNU C++ compiler (multilib files) ii g++-multilib 4:4.7.2-1ubuntu2 amd64 GNU C++ compiler (multilib files) ii libconfig++9:amd64 1.4.8-5 amd64 parsing and manipulation of structured configuration files(C++ binding) un libg++2.8-dev <none> (no description available) un libg++27-dev <none> (no description available) un libg++272-dev <none> (no description available) caibbor@helios ~ $ dpkg -l '*multilib*' Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-==========================================-==========================-==========================-========================================================================================== un g++-4.6-multilib <none> (no description available) ii g++-4.7-multilib 4.7.2-2ubuntu1 amd64 GNU C++ compiler (multilib files) ii g++-multilib 4:4.7.2-1ubuntu2 amd64 GNU C++ compiler (multilib files) un gcc-4.6-multilib <none> (no description available) ii gcc-4.7-multilib 4.7.2-2ubuntu1 amd64 GNU C compiler (multilib files) ii gcc-multilib 4:4.7.2-1ubuntu2 amd64 GNU C compiler (multilib files) caibbor@helios ~ $ dpkg -l '*libc6*' Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-==========================================-==========================-==========================-========================================================================================== ii libc6:amd64 2.15-0ubuntu20 amd64 Embedded GNU C Library: Shared libraries ii libc6:i386 2.15-0ubuntu20 i386 Embedded GNU C Library: Shared libraries un libc6-amd64 <none> (no description available) ii libc6-dbg:amd64 2.15-0ubuntu20 amd64 Embedded GNU C Library: detached debugging symbols ii libc6-dev:amd64 2.15-0ubuntu20 amd64 Embedded GNU C Library: Development Libraries and Header Files ii libc6-dev:i386 2.15-0ubuntu20 i386 Embedded GNU C Library: Development Libraries and Header Files ii libc6-dev-i386 2.15-0ubuntu20 amd64 Embedded GNU C Library: 32-bit development libraries for AMD64 ii libc6-i386 2.15-0ubuntu20 amd64 Embedded GNU C Library: 32-bit shared libraries for AMD64 un libc6-i686 <none> (no description available) un libc6.1 <none> (no description available) un libc6.1-dev <none> (no description available)
- 03-21-2013 #2Just Joined!
- Join Date
- Sep 2012
- Location
- Nashville, TN
- Posts
- 67
/usr/lib32 is where Linux stores it's 32 bit shared libraries. Like libdvdcss.so or libreadline.so. /usr/lib/gcc/i686-linux-gnu/ I would think is where it contains some of the header files for development using gcc or g++. However you say it is empty which is interesting. Mine show a couple of object files but for the most part the main files for c or c++ exists in /usr/include/
- 03-21-2013 #3Just Joined!
- Join Date
- Aug 2010
- Posts
- 31
no, this is what I said:
/usr/lib/gcc/i686-linux-gnu/ has lots of stuff, my problem is that g++, when being explicitly told to use 32-bit executables, is looking in /usr/lib/gcc/x86_64-linux-gnu/ instead of /usr/lib/gcc/i686-linux-gnu/ as I show via g++ -m32 -v in the original post.
How do I get it to look in the right place? (right place being /usr/lib/gcc/i686-linux-gnu/)
- 03-21-2013 #4Just Joined!
- Join Date
- Sep 2012
- Location
- Nashville, TN
- Posts
- 67
Ok sorry for mis reading that. Try doing the following
Code:g++ -m32 -c test.cpp -o test.o g++ -m32 -L/usr/lib/gcc/i686-linux-gnu/ -lstdc++ test.o -o test # If that doesn't work try changing -L to -L/usr/lib32
- 03-21-2013 #5Just Joined!
- Join Date
- Aug 2010
- Posts
- 31
- 03-22-2013 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,199
Hi.
I installed g++-multilib. Then I ran this script:
producing:Code:#!/usr/bin/env bash # @(#) s1 Demonstrate g++ compile, link, execute. # Section 1, setup, pre-solution. # Infrastructure details, environment, commands for forum posts. # Uncomment export command to test script as external user. # export PATH="/usr/local/bin:/usr/bin:/bin" set +o nounset pe() { for i;do printf "%s" "$i";done; printf "\n"; } pl() { pe;pe "-----" ;pe "$*"; } C=$HOME/bin/context && [ -f $C ] && . $C g++ ldd set -o nounset pe FILE=${1-one.cpp} # Section 2, display file. head $FILE # Section 3, solution. pl " Results, 32-bit object files are:" rm -f *.o a.out g++ -m32 -c $FILE file *.o pl " Output from 32-bit link and execute:" g++ -m32 *.o -lm ./a.out pl " Libraries used by this executable, $( file a.out):" ldd a.out # Remove debris. rm -f a.out *.o exit 0
A guess -- ldconfig wasn't run to set the libraries. That was the last reported step when I installed g++-multilib.Code:$ ./s1 Environment: LC_ALL = C, LANG = en_US.UTF-8 (Versions displayed with local utility "version") OS, ker|rel, machine: Linux, 3.0.0-13-generic, x86_64 Distribution : Ubuntu 11.10 (oneiric on Debian wheezy/sid) bash GNU bash 4.2.10 g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 ldd (Ubuntu EGLIBC 2.13-20ubuntu5.3) 2.13 #include <iostream> using namespace std; int main() { cout << " Hello, world from c++" << endl; return ( 0 ); } ----- Results, 32-bit object files are: one.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped ----- Output from 32-bit link and execute: Hello, world from c++ ----- Libraries used by this executable, a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped: linux-gate.so.1 => (0xf7747000) libstdc++.so.6 => /usr/lib32/libstdc++.so.6 (0xf764a000) libc.so.6 => /lib32/libc.so.6 (0xf74cb000) libm.so.6 => /lib32/libm.so.6 (0xf74a1000) /lib/ld-linux.so.2 (0xf7748000) libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0xf7483000)
Best wishes ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote

