Monday, September 18, 2017

installing GCC / C++

One of the most simplest way to run C++ on linux terminal is installing GCC compiler, although there more steps that needs to be done. Usually gcc compile outcome into a text file which your editor sometimes cannot event read from it unless you adjust the binary for it.
in this case i am going to show you how to install GCC and how run through from terminal in both ubuntu and mac os.

Please note that becareful when you choose gcc version, some version doesn't have c++ features.
According  GNU.ORG gcc4.7 supports lots  c++ 11 features.
As of the gcc-4.8 release, gcc-4.7 does not support 8 out of 64 features (See C++0x/C++11 Support in GCC)
  • Language Features
    - Rvalue references for *this
    - Generalized attributes
    - Alignment support
    - Inheriting constructors
    Concurreny
    - Bidirectional Fences
    - Memory model
    - Abandoning a process and at_quick_exit
    - Thread-local storage 
    

Adding the toolchain/test PPA: (if you dont have it)

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50

Building GCC-4.8 from source:
If you need gcc-4.8 on 12.04 now, your only option is to build it from source.
Please read the GCC installation FAQ prior to installation.
You can download gcc-4.8 from one of gnu.org's mirror sites or directly from their SVN server.
Here is an example of steps to compile from source (see here for additional details.) Note that these may vary depending on your system and preferences.
  1. Download the source code
    • Make a build directory ( mkdir gcc-build && cd gcc-build)
    • Download the source file: wget http://www.netgull.com/gcc/releases/gcc-4.8.0/gcc-4.8.0.tar.bz2 (adjust this command to use an appropriate mirror site.
    • Unzip the file (tar -xvjf <file name>)
  2. Install some additional libraries (sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libc6-dev)
  3. Compile the source: ./gcc-4.8.0/configure --prefix=/app/gcc/4.8.0
  4. Run make (This will take some time to complete. Go make some coffee, or bake some cookies. ;-))
  5. Install the code: sudo make install
Once this process has completed, run the command gcc --version to verify that the installation has completed successfully. 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Data Structures : Tree Traversals

(Week 2) Tree traversals are one of the most important algorithm in computer science because sometimes we don't have lin...