19

i recently got Oracle Solaris on my VM to test some code on it, i was unable to install gcc since i dont really know how, i googled alot but all info is about oracle compilers, i needed GCC, any idea where can i get GCC or how to install it?

thanks

wkl
  • 77,184
  • 16
  • 165
  • 176
killercode
  • 1,666
  • 5
  • 29
  • 42

9 Answers9

20

The original answer applied to Solaris 11 Express/non-official release - if you're doing this today with a full release of Solaris 11.x, use the pkg install command like you see in xavier's response.

Run this command from your terminal to install GCC.

For GCC 3.4.x

pkg install gcc-3

For GCC 4.5.x

pkg install gcc-45

For GCC 4.7.x

pkg install gcc-47

For GCC 4.8.x

pkg install gcc-48

The gcc command should then already be placed in your path /usr/bin/gcc, which is a symlink).


Old Answer Solaris 11 should already have gcc installed in /usr/sfw/bin/, but it's probably not in your PATH. Try this at the prompt: /usr/sfw/bin/gcc

Community
  • 1
  • 1
wkl
  • 77,184
  • 16
  • 165
  • 176
  • 3
    no, its not there, i checked, and just checked again, i also ran a find command – killercode Jan 12 '11 at 01:18
  • 10
    `sudo pkg install gcc-3` then to install the package. `pkg search gcc` could have found that package name for you. – alanc Jan 12 '11 at 03:33
  • ty, it worked :), but just 1 qustion, its version 3.4 from 2005, no newer versions? – killercode Jan 12 '11 at 05:39
  • @killercode - sorry I didn't respond sooner - no, the official package is just GCC 3.4.x. When I did software ports on Solaris, a client requested GCC 4.4, which meant I had to build my own GCC 4.4 with the GCC 3.4 provided. – wkl Feb 14 '11 at 19:52
  • The actual Solaris 11 release (November 2011) now has both 3.4.3 and 4.5.2. The Solaris 11 Express preview from November 2010 only had the older 3.4.3. – alanc Dec 27 '11 at 19:52
  • Blast from the past. I'm now back in Solaris land and I am using pkgutil to make life easier: http://pkgutil.net/ – wkl Dec 27 '11 at 21:16
  • I did have to install the compiler, but no need to change my PATH variable. – Alexis Wilke May 06 '13 at 01:25
  • 1
    This answer is incorrect (but may have been correct if it was written for a *pre-release* of Solaris 11 back then, dunno ?). Anyways: `gcc` on Solaris 11 doesn't live in `/usr/sfw/bin`. You are confusing with Solaris 10. – peterh Feb 20 '16 at 09:06
  • @peterh At the time this question was posed, Solaris 11 wasn't out yet, only Solaris 11 Express or some prerelease I had access to, which was basically Solaris 10 with some intermediate transition features. – wkl Feb 20 '16 at 13:35
16

Two steps:

  1. pkg install gcc-45
  2. pkg install system/header

that is all

if you see more info http://blog.csdn.net/zjg555543/article/details/8217769

Pedryk
  • 1,643
  • 1
  • 13
  • 28
xavier
  • 161
  • 1
  • 2
  • `pkg install gcc-45` also installs `system/header` so no need for the 2nd command. – glebd Jan 21 '14 at 15:48
  • I did not get `system/header` on OpenIndiana with the first command, so I warmly thank you for the second command. – user7610 Aug 24 '17 at 14:09
3

Just download gcc from its homepage, follow one of the mirror links to fetch the latest binary package (in .tar.gz or tar.bz2 format), and use traditional steps to build:

  1. ./configure --<> // give your options
  2. make
  3. make install

The good news is you can customize what you need and always stay with the latest, while bad part is you may lose the power to debug with mdb/adb - we are facing such problems with latest GCC 4.6.x

Fei
  • 1,450
  • 1
  • 17
  • 30
  • 1
    @AlexisWilke Our solaris box was shipped with a default GCC in /usr/sfw/bin, which can be used to build something at least. – Fei May 09 '13 at 01:23
  • Interesting. I installed Solaris from CD in a virtual box and the /usr/sfw directory did not exist. birryree mentioned that directory too in his answer... but I could not see it and still cannot see it! – Alexis Wilke May 10 '13 at 21:33
  • 1
    alexis - gcc has been buildable without a compiler since the mid 90's. it's slow, and involved. any good compiler can be boostrapped from lower level tools (bison, yacc, ar, etc.) – him Sep 12 '13 at 17:45
2
pkg install gcc 

worked for me

This will install entire gcc collection on your machine. Which anyways will be required

2

My Solaris 2.11 does NOT have internet access :/

What work for me:

(1) I use this link as guideline
(2) From my windows machine, download gcc at one of their mirror sites, i used here, normally the closer the better
(3) Upload gcc-9.2.0.tar.gz to target /tmp directory using WinSCP
(4) tar -xvf gcc-9.2.0.tar.gz
(5) cd gcc-9.2.0
(6) mkdir /usr/local/gcc
(7) cd /usr/local/gcc
(8) /tmp/gcc-9.2.0/configure -v --program-suffix=9.2

At this point, you might get this error:
Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.

(9) Manually download the required files here.
Note: To know what files are required, check contrib/download_prerequisites
(10)Copy over the files in (9) to /tmp/gcc-9.2.0
(11)Extract, then create shortcuts: ln -s gmp-6.1.0 gmp, ln -s mpc-1.0.3 mpc, ln -s mpfr-3.1.4 mpfr, ln -s isl-0.18 isl
(12)/tmp/gcc-9.2.0/configure -v --program-suffix=9.2 --enable-languages=c,c++ -v
(13) nohup gmake & (At this point it's going to take some time...mine took ~6 hours. Use -j option if you can, to gmake it faster )
(14) gmake install
(15) /usr/local/bin# ./gcc9.2 --version
gcc9.2 (GCC) 9.2.0 Copyright (C) 2019 Free Software Foundation, Inc.

Voila! :-)

jumping_monkey
  • 5,941
  • 2
  • 43
  • 58
2

Solaris 10 and prior version :

/usr/sfw/bin/gcc works.

Solaris 11 :

pkg install gcc-3

2sb
  • 629
  • 2
  • 12
  • 26
1

I had the same problem and 'pkg install gcc-3' worked for me.

Chamila Wijayarathna
  • 1,815
  • 5
  • 30
  • 54
1

I'll quote the answer from unix.stackexchange.com.

On Solaris 11 gcc is not installed by default. Normally you'll want more than just the compiler itself so my answer will include all the usual suspects for building open source software on Solaris that you've downloaded from somewhere in source code format.

By far the easiest is to use IPS to install it using the commands below (while being root or other superuser):

pkg install pkg://solaris/developer/build/gnu-make \
            pkg://solaris/developer/build/make \
            pkg://solaris/developer/gcc \
            pkg://solaris/system/header \
            pkg://solaris/developer/build/autoconf \
            pkg://solaris/developer/build/automake

(I use fully qualified package names here, that is not really necessary)

Note that some of the packages are available in the official repo in various versions. If you just reference developer/gcc then you'll at the time of writing this get GNU C v4.8.2, but you may explicitly ask for a prior version, e.g. by using package name such as developer/gcc-45.

Community
  • 1
  • 1
peterh
  • 18,404
  • 12
  • 87
  • 115
1

You can install gcc 4.3 from OpenCSW:

pkg-get -i gcc4code gcc4g++

I also had to run mkheaders manually after the install.

Gene Vincent
  • 5,237
  • 9
  • 50
  • 86