Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, October 23, 2012

How to install GCC 4.7.2 in ubuntu 12.04 for c++11

Ubuntu 12.04 comes with GCC compiler for C language only (not for c++).
First check which version of GCC ubuntu already installed. If it is <4.7.2 then proceed.
  • gcc is used to compile C program
  • g++ is used to compile C++ program
  1. gcc -v (to check the gcc version)
  2. g++ -v (to check the g++ version)
  3. sudo apt-get update
  4. sudo apt-get install build-essential (to install g++ & some other other stuff)
  5. sudo apt-get update
  6. g++ -v (now check g++ is installed)

(Now add source from which we get GCC latest stable version)
  1. sudo add-apt-repository ppa:ubuntu-toolchain-r/test
  2. sudo apt-get update
  3. sudo apt-get install gcc-4.7
  4. sudo apt-get install g++-4.7
  • ls -lh /usr/bin/g++*

Install Alternatives(remember the version of gcc/g++):
  1. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 10
  2. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20
  1. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 10
  2. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 20
  1. sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 (avoid the warning)
  2. sudo update-alternatives --set cc /usr/bin/gcc
  1. sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
  2. sudo update-alternatives --set c++ /usr/bin/g++
  • gcc -v
  • g++ -v (conform that you successfully installed the GCC)

configuring the default commands for gcc, g++:
  1. sudo update-alternatives --config gcc
  2. sudo update-alternatives --config g++
Source:
  1. Repository
  2. Nice detailed explanation
  3. Install Alternatives

Wednesday, March 28, 2012

About SWAP in linux

what is swap?
swap space is the area on a HD which is part of the VM of your machine.
swap space temporarily hold a memory pages that are inactive.

why do i need swap?
  1. Memory consuming programs Sometimes, a large program (like OpenOffice, Neverwinter Nights, or a video editor) make the entire system need extra memory.
  2. Hibernation (suspend-to-disk) The hibernation feature (suspend-to-disk) writes out the contents of RAM to the swap partition before turning off the machine.
  3. Optimizing memory usage
  4. Optimizing Swap performance

How much swap do i need?
As a base minimum, it's highly recommended that the swap space should be equal to the amount of physical memory (RAM).

Example Scenarios:
  • Low RAM and low disk space With 512 MiB RAM and 30 GB hard disk, use  512 MiB for swap since RAM is very low.
  • Low RAM and high disk space With 512 MiB RAM and 100 GB hard disk, use 1 GiB for swap since RAM is very low and hard disk space is plentiful.
  • High RAM and low disk space With 2 GiB RAM and 30 GB hard disk, use 1 GiB for swap since hard disk space is very low.
  • High RAM and high disk space With 2 GiB RAM and 100 GB hard disk, use 2 GiB for swap since hard disk space is plentiful.

Tuesday, March 20, 2012

What is kernel

What is linux -- it is a kernel.
What is GNU\Linux -- linux operating system.

Linux is the name of the kernel. The kernel is the core part of an operating system that keeps track of everything. The kernel is both a fence and a gate. As a gate, it allows programs to access hardware in a uniform way. Without the kernel, you would have to write programs to deal with every device model ever made. The kernel handles all device-specific interactions so you don't have to. It also handles file access and interaction between processes.

The kernel also controls the flow of information between programs. The kernel is a program's gate to the world around it. Every time that data moves between processes, the kernel controls the messaging.

As a fence
, the kernel prevents programs from accidentally overwriting each other's data and from accessing files and devices that they don't have permission to. It limits the amount of damage a poorly-written program can do to other running programs.

In our case, the kernel is Linux. Now, the kernel all by itself won't do anything. You can't even boot up a computer with just a kernel. Think of the kernel as the water pipes for a house. Without the pipes, the faucets won't work, but the pipes are pretty useless if there are no faucets. Together, the user applications (from the GNU project and other places) and the kernel (Linux) make up the entire operating system, GNU/Linux.