Installing C++11 on Ubuntu 12.04 LTS

Installing C++11 on Ubuntu 12.04 LTS

I used to code in C.  In fact, I wrote a lot of C code for many years starting back in the 80’s and probably through to the mid 90’s.  Recently, I’ve become interested in high speed messaging and wanted to learn more about IP multicast.  As with all things code related, I find the best way to learn is to write some code.  So I installed Eclipse for C/C++ and the eclipse C development tools and jumped write in (pardon the pun).  I wrote a couple of programs, but then quickly ran into some issues, not big issues, but things to contend with if I wanted to write code the way I usually write code.

For example, I wanted a threaded echo server, with the receive and send threads sharing data via a queue.  This takes all of 5 minutes to do in Java.  Not so in C.  I was looking at using PTHREADS and BOOST.  I’ve had *really* bad experiences with BOOST in the past, and granted it was over 10 years ago, it was so painful that it still hurts.  I remember debugging code that was going into the Pacific Stock Exchange integrating Javelin’s FIX engine and NEON’s MQ Series Integrator and having nothing but problems and risking a deadline.  So I wasn’t to excited.

I had been reading about C++11 and purchased Stroustrup’s new book, “The C++ Programming Language,” Fourth Edition, which covers C++11 as well as his original work covered C++.  In the longish preamble before we actually get to code, Bjarne states that good C code looks like good C++ code.  He also stated that C++11 included things like threading, and all of the wholesome goodness of BOOST without BOOST.  I was intrigued.  The idea of utilizing native concurrency functionality and such exotic things as lambda’s in C++ was too much to pass up.

The first thing to do was to install C++11 on Ubuntu 12.04 LTS – my preferred environment.  This is what I did:

First, we need to add a C++ repository, this one has C++:

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update

Then, we search for the latest and greatest gcc and g++:

$ sudo apt-cache search "g\+\+"

And I found:

g++-4.8 - GNU C++ compiler

So I installed:

$ sudo apt-get install gcc-4.8 g++-4.8

At this point, I had whatever I had before for gcc and g++, and I wanted to keep them. So by using alternatives, I was able to easily change from that already installed version and the latest and greatest by doing this:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --config gcc

After installing that, I installed one more package:

sudo apt-get install systemtap

Eclipse requires this to build and run from within the IDE.

And that was it. I went and created a default Hello World C++ project in Eclipse using the Linux (vs CROSS) compiler settings, ran it, and received this:

#include
using namespace std;

int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}

Produced this:

!!!Hello World!!!

Which appears to mean that everything is working correctly.

I hope this was helpful, and thanks for reading!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值