Compile and install GCC 4.9 and verify the use

Source: Internet
Author: User
Tags function definition gmp
Compile and install GCC 4.9 and verify the use

1. Preparation environment (GCC compiler)
CentOS 6.3
Cat/proc/version
Linux version 2.6.32-279.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (G CC) #1 SMP Fri June 12:19:21 UTC 2012
GCC--version
GCC (gcc) 4.4.6 20120305 (Red Hat 4.4.6-4)

2. Preparation of documents
Gcc-4.9.0.tar.gz
website (http://gcc.gnu.org/) Download:

Ftp://mirrors.kernel.org/gnu/gcc/gcc-4.9.0/gcc-4.9.0.tar.gz

http://gcc.petsads.us/releases/

3. Installation Steps
3.1. Decompression gcc-4.9.0.tar.gz
Get directory gcc-4.9.0, enter directory
#tar-xvzf gcc-4.9.0.tar.gz
#cd gcc-4.9.0

3.2. Download compilation Preparation File
The main requirements are the following library files (need full version, download all files)
mpfr=mpfr-2.4.2
gmp=gmp-4.3.2
mpc=mpc-0.8.1
isl=isl-0.12.2
cloog=cloog-0.18.1
Execute./contrib/download_prerequisites
If the compiler can not access the Internet, directly open the text file download_prerequisites, put the inside
Dependent libraries are downloaded back, placed in the specified directory, then annotated download command, executed again
Contrib/download_prerequisites, unzip the related files and set up links.
#vi contrib/download_prerequisites
Note wget related content, manually download these files back, copy to the working directory gcc-4.9.0.
#./contrib/download_prerequisites

3.3. Create the compilation directory and compile the installation
#mkdir. /gcc-build-4.9.0

#cd. /gcc-build-4.9.0

#.. /gcc-4.9.0/configure--prefix=/usr/local/gcc-4.9.0--enable-stage1-checking=release--enable-stage1-languages=c,c ++,go

#make-j 4
#make Install
Install after compiling to/usr/local/gcc-4.9.0

3.4. Verifying installation
#cd/usr/local/gcc-4.9.0
#./bin/gcc-v
See version information
...
Threading Model: POSIX
GCC version 4.9.0 (GCC)

3.5. Verify the Compilation function (c + + 2011)
Constructs the code file Test_gcc4.9.cpp, which reads as follows:

#include <string.h>
#include <iostream>
#include <stdio.h>
#include <thread>
#include <future>
using namespace Std;

Template<typename t> t Stringcat (t &x,t &y)
{
std::cout<< "stringcat start ..." <<endl;
x = = x;
y = = y;

Sleep Specifies the number of milliseconds
Std::this_thread::sleep_for (Std::chrono::milliseconds (1000));

std::cout<< "Stringcat end ..." <<endl;
return x + y;
}

Template<typename T> class Ctheadoperator
{
Public
Create a thread initiate an asynchronous call
void CreateThread ();
};

Template<typename t> void Ctheadoperator<t>::createthread ()
{
std::string x = "X", y = "Y";
Auto B = Std::bind (stringcat<std::string>,x,y);
std::cout<< "CreateThread wait stringcat....\n";
Std::thread TP (b);
Tp.join ();
Watch for changes in return values
std::cout<< "No parameters Modified" <<x<< "" <<y<<endl;
}

int main (int argc,char *argv[])
{
ctheadoperator<std::string> TP;
Tp.createthread ();


return 0;
}

Compile execution, pay attention to the parameter-std=c++11,-lstdc++, prove to be using the new standard
View the linked dynamic library, which is the new library
The compiled file is executable and performing normally
#/usr/local/gcc-4.9.0/bin/g++-wwrite-strings-std=c++11 Test_gcc4.9.cpp-o test_gcc4.9-i/usr/local/gcc-4.9.0/ Include-l/usr/local/gcc-4.9.0/lib64-lstdc++-fpermissive-lpthread
#ldd test_gcc4.9
Linux-vdso.so.1 => (0x00007fff2fbff000)
Libstdc++.so.6 =>/usr/local/gcc-4.9.0/lib64/libstdc++.so.6 (0x00007f94ae037000)
libpthread.so.0 =>/lib64/libpthread.so.0 (0x0000003431800000)
Libm.so.6 =>/lib64/libm.so.6 (0x0000003431000000)
Libgcc_s.so.1 =>/usr/local/gcc-4.9.0/lib64/libgcc_s.so.1 (0x00007f94ade07000)
Libc.so.6 =>/lib64/libc.so.6 (0x0000003430c00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003430800000
#./test_gcc4.9
CreateThread wait Stringcat ....
Stringcat start ....
Stringcat end ....
No parameters modified X y

3.6. Verify compile function (C11), Missing Threads.h file, compilation failed
Create a file test_gcc4.9.c that reads as follows:
#include <string.h>
#include <stdio.h>
Note This line, the path is inconsistent
#include <thr/threads.h>

Note that the function definition must be
typedef int (*_thrd_start_t) (void *);
int fun (void *data)
{
printf ("thread=%d\n", Thrd_current ());
Std::map<std::string, std::string> m;
M.insert (Std::make_pair ("A1", "B1"));
Auto result = M.insert (Std::make_pair ("A1", "B1"));
if (Result.second)
//{
printf ("M insert true%d,", thrd_current ());
Std:std::cout << "key=" << result.first->first << ", value=" << Result.first->second << Endl;
//}
Else
//{
printf ("m insert Fail%d\n", thrd_current ());
//}
return 0;
}

int main (int argc,char *argv[])
{
Thrd_t Loc;
Thrd_create (&loc, fun,0);
Thrd_join (loc,0);
return 0;
}

Compile execution, pay attention to the parameter-std=c11,-lgcc_s, prove to be using the new standard
View the linked dynamic library, which is the new library
Alas, failed to compile successfully, unable to perform normal!!!
#/usr/local/gcc-4.9.0/bin/gcc-wwrite-strings-std=c11 Test_gcc4.9.c-o Test_gcc4.9-i/usr/local/gcc-4.9.0/include-l /usr/local/gcc-4.9.0/lib64-lgcc_s-lpthread;
#test_gcc4.9.C:4:21: Fatal error: threads.h: no file or directory
#include <threads.h>
^
Compilation interrupted.

Postscript:
After installing the free Visual Studio Express 2013, it works correctly after compiling.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.