{"id":658,"date":"2012-04-02T16:08:51","date_gmt":"2012-04-02T16:08:51","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=658"},"modified":"2026-06-28T17:38:27","modified_gmt":"2026-06-29T00:38:27","slug":"bash-script-to-install-gcc-4-70-and-boost-1-49","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=658","title":{"rendered":"Bash script to install gcc 4.7.0 and boost 1.49"},"content":{"rendered":"I recently wanted to build gcc 4.7.0 on CentOS 5.5 to get access to more C++11 features so I put together <a href=\"http:\/\/projects.joelinoff.com\/gcc-4.7.0\/bld.sh.txt\">this<\/a> script to do all of the work. It is released in text mode so that you can cut-n-paste it from the web page. The shell version is also available: <a href=\"http:\/\/projects.joelinoff.com\/gcc-4.7.0\/bld.sh\">http:\/\/projects.joelinoff.com\/gcc-4.7.0\/bld.sh<\/a> if you want to download it directly using a tool like wget.\n\nThe full installation of gcc-4.7.0 and boost-1.49 requires about 4GB of disk space. After the build is complete you can delete the archives, bld and src directory trees to reclaim about 3.4GB of disk space.\n<!--more-->\n\n<blockquote>On 2012-04-14 I updated the script to install binutils-2.22 as well. You can disable it by simply commenting out  line 139.<br>\nOn 2012-09-22 I added page for installing gcc-4.7.2 and boost 1.51.0 <a href=\"http:\/\/joelinoff.com\/blog\/?p=811\">here<\/a>.\n<\/blockquote>\n\n<h2>Using bld.sh<\/h2>\nHere is how you might use build script described above to install gcc-4.7.0 and boost-1.49 on your system.\n\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">#!\/bin\/bash\numask 0\nmkdir -p \/shared\/tools\/gcc\/gcc-4.7.0\ncd \/shared\/tools\/gcc\/gcc-4.7.0\nwget http:\/\/projects.joelinoff.com\/gcc-4.7.0\/bld.sh\nchmod a+x bld.sh\n.\/bld.sh 2&gt;&amp;1 | tee bld.log<\/code><\/pre>\n\n\n<h2>Simple Test Program: x.cc<\/h2>\nIf you want, you can create a simple program like this:\n\n\n<pre class=\"wp-block-code language-c++\"><code class=\"language-c++\">\/\/ Test the gcc 4.7.0 compiler.\n#include &lt;iostream&gt;\n#include &lt;boost\/algorithm\/string.hpp&gt;\nusing namespace std;\nusing namespace boost;\nint main()\n{\n  string s1(\" hello world! \");\n  cout &lt;&lt; \"value      : '\" &lt;&lt; s1 &lt;&lt; \"'\" &lt;&lt;endl;\n\n  to_upper(s1);\n  cout &lt;&lt; \"to_upper() : '\" &lt;&lt; s1 &lt;&lt; \"'\" &lt;&lt;endl;\n\n  trim(s1);\n  cout &lt;&lt; \"trim()     : '\" &lt;&lt; s1 &lt;&lt; \"'\" &lt;&lt;endl;\n\n  return 0;\n}<\/code><\/pre>\n\n\nThen compile, link and run it as follows.\n\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">#!\/bin\/bash\nGHM=\"\/shared\/tools\/gcc\/gcc-4.7.0\/rtf\"\nGXX=\"${GHM}\/bin\/g++\"   # OR PATH=\"${GHM}\/bin:${PATH}\"\nexport LD_LIBRARY_PATH=\"${GHM}\/lib64\"\n$GXX -O3 -Wall -o x.exe x.cc\n.\/x.exe\n# Expected output\n# value      : ' hello world! '\n# to_upper() : ' HELLO WORLD! '\n# trim()     : 'HELLO WORLD!'<\/code><\/pre>\n\n\nor if you prefer make&#8230;\n\n\n<pre class=\"wp-block-code language-make\"><code class=\"language-make\">GHM=\"\/home\/jlinoff\/work\/gcc-4.7.0\/rtf\"\nGXX=\"${GHM}\/bin\/g++\" # OR PATH=\"${GHM}\/bin:${PATH}\"\n\nall: x.exe\n\t.\/x.exe\n\nclean:\n\t\\rm -f *~ *exe\n\n%.exe : %.cc\n\t@export LD_LIBRARY_PATH=\"$(GHM)\/lib64\" ; \\\n\t$(GXX) -O3 -Wall -o $@ $&lt;<\/code><\/pre>\n\n\n<h2>Final Thoughts<\/h2>\nThis script has been tested on CentOS 5.5. \n\nNote that I decided to use the latest version CLooG (0.17.0) so I had to put in a small hack to fix the gcc\/g++ source code. Specifically I had to change LANGUAGE_C to CLOOG_LANGUAGE_C in the &lt;gcc-4.7.0-source&gt;\/gcc\/graphite-clast-to-gimple.c to track the same change in CLooG. This hack is done automatically by the script. I also had to turn off version checking because it specifically requires 0.16.0.\n\nPlease report problems or suggestions via the comments section.\n\nEnjoy!\n\n\n","protected":false},"excerpt":{"rendered":"<p>I recently wanted to build gcc 4.7.0 on CentOS 5.5 to get access to more C++11 features so I put together this script to do all of the work. It is released in text mode so that you can cut-n-paste it from the web page. The shell version is also available: http:\/\/projects.joelinoff.com\/gcc-4.7.0\/bld.sh if you want &hellip; <a href=\"https:\/\/joelinoff.com\/blog\/?p=658\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Bash script to install gcc 4.7.0 and boost 1.49<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15,5],"tags":[],"class_list":["post-658","post","type-post","status-publish","format-standard","hentry","category-bash","category-programming"],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=658"}],"version-history":[{"count":8,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/658\/revisions"}],"predecessor-version":[{"id":1791,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/658\/revisions\/1791"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}