Jim Dickenson Thanks, I got that version a few weeks ago. I am trying to get version 3.51 stuff working on my Mac because it is easier for me to work on this system than on my Linux box. I also wanted to turn off -O2 as I am working with Venu trying to debug a problem I have been having.
I had to compile a 32-bit application using GNU gcc on the 64-bit version of Linux.
Luckily, gcc man page directed me to the ‘-m32’ and ‘-m64’ options. These options generate code for 32-bit or 64-bit environments, respectively.
Luckily, gcc man page directed me to the ‘-m32’ and ‘-m64’ options. These options generate code for 32-bit or 64-bit environments, respectively.
- The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on any i386 system.
- The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture.
You can pass -m64 or -m32 options as follows to Gnu gcc
For 32 bit version:
For 64 bit version :
Run it as follows:
Output:
$ gcc -m32 -o output32 hello.c
For 64 bit version :
$ gcc -m64 -o output64 hello.c
Run it as follows:
$ ./output32
Output:
Now let us see 64 bit output:
$ ./output64
Sample code – hello.c
A note about glibc-devel on 64 bit systems
You may see an error as follows on 64 bit system when you try to build 32 bit app:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h:
This error message shows up on the 64 bit systems where GCC multilib feature is enabled, and it indicates that 32 bit version of libc is not installed. To fix this problem, on a CentOS/RHEL 5.x type the following yum command:
To fix this problem, on a CentOS/RHEL 6.x type the following yum command:
To fix this problem on a Debian or Ubuntu Linux type the following apt-get command:
To fix this problem on a Suse (SLES) / OpenSUSE Linux type the following zypper command:
# yum -y install glibc-devel.i386 libstdc++-devel.i386
To fix this problem, on a CentOS/RHEL 6.x type the following yum command:
# yum -y install glibc-devel.i686 glibc-devel ibstdc++-devel.i686
To fix this problem on a Debian or Ubuntu Linux type the following apt-get command:
$ sudo apt-get install g++-multilib libc6-dev-i386
To fix this problem on a Suse (SLES) / OpenSUSE Linux type the following zypper command:
# zypper in glibc-devel-32bit
See also
- Man page – gcc(1)
# Additional correction by Braden B and others; Editing by VG – log #
ADVERTISEMENTS
I have Mac OS X Mountain Lion. I need to compile a few apps and Perl modules. I already installed Xcode from app store but I’m unable to find gcc compiler or make command. How do I install gcc on Mac OS X 10.8.x?Xcode includes command line development tools such as gcc and friends.
Advertisements
Step #1: Install Xcode on a Apple Mac OS X
First, make sure Xcode is installed. If it is not installed on OS X, visit app store and install Xcode.
Step #2: Install gcc/LLVM compiler on OS X
Once installed, open Xcode and visit:
Xcode menu > Preferences > Downloads > choose 'Command line tools' > Click 'Install' button:
Xcode will download package and install copies of the core command line tools and system headers into system folders, including the LLVM compiler, linker, and build tools.
Step #3: Verification
Open a terminal app and type the following commands:
Sample outputs:
$ gcc --version
$ whereis gcc
$ whereis make
Sample outputs:
Testing sample “Hello world” C program
Create a text file called a.c as follows using a text editor such as vi or cat command:
To compile, enter:
Run it as follows:
Sample outputs:
$ make a
Run it as follows:
$ ./a
Sample outputs:
See also
And, there you have it, the gcc version 4.2.1 installed and working correctly on the latest version of Mac OS X 10.8.4. In Apple’s version of GCC, both cc and gcc are actually symbolic links to the llvm-gcc compiler. Similarly, c++ and g++ are links to llvm-g++. For more information and examples see the following man pages:
$ man gcc
$ man make
5 of 13 in the Linux GNU/GCC Compilers Tutorial series. Keep reading the rest of the series:
- Mac OS X: Install GCC Compiler with Xcode
ADVERTISEMENTS