Build a C ++ runtime environment on CentOS 6.6

Source: Internet
Author: User
Tags dname

Build a C ++ runtime environment on CentOS 6.6

1. Install the runtime environment

#yuminstallgcc-c++

Note: Both gcc-c ++ and libstdc ++-devel are installed.

2. Check whether g ++ is successfully installed.

[Root @ MyRHEL desktop]#g++-v

Use built-in specs.

Goals: x86_64-redhat-linux

Configuration :.. /configure -- prefix =/usr -- mandir =/usr/share/man -- infodir =/usr/share/info -- with-bugurl = http://bugzilla.redhat.com/bugzilla -- enable-bootstrap -- enable-shared -- enable-threads = posix -- enable-checking = release -- with-system-zlib -- enable-_ cxa_atexit -- disable-libunwind-exceptions -- enable-gnu-unique-object -- enable- ages = c, c ++, objc, obj-c ++, java, fortran, ada -- enable-java-awt = gtk -- disable-dssi -- with-java-home =/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre -- enable-libgcj-multifile -- enable-java -maintainer-mode -- with-ecj-jar =/usr/share/java/eclipse-ecj.jar -- disable-libjava-multilib -- with-ppl -- with-cloog -- with-tune = generic -- with-arch_32 = i686 -- build = x86_64-redhat-linux

Thread model: posix

Gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)

3. Test

(1) Test the c language program testc. c.

#include<stdio.h>intmain(){printf("HelloC!\n");return0;}

Run:

#gcctestc.c-otestc#./testc

(2) test C ++ program test. cpp

#include<iostream>usingnamespacestd;intmain(){cout<<"ComeupandC++mesometime.";cout<<endl;cout<<"Youwon'tregretit!"<<endl;return10;}

Run:

#g++-otest1test.cpp#./test1

4. Install OracleClient

Mainly install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm and oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm.

#rpm-ivhoracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm#rpm–ivhoracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

5 configuration

(1) configure the ld. so. conf file and enter the following content:

#vi/etc/ld.so.confincludeld.so.conf.d/*.conf/usr/lib/oracle/11.2/client64/lib

(2) configure the/etc/hosts file (enter the IP address and Host Name of the Linux host) and enter the following content:

#vi/etc/hosts127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6192.168.48.128MyRHEL

6. Test the connection to the Oracle database

(1) create a connclient. cpp file and enter the following content:

[Root @ MyRHEL test] # vi connclient. cpp

# Include <iostream>

# Include <string>

# Include <occi. h>

UsingNamespacestd;

UsingNamespaceoracle: Occi;

Intmain()

{

Environment* Env;

Connection* Conn;

Statement* Stmt;

String struser("Scott");

String strpwd("Orcl0991");

String strconn_string("10.208.17.206: 1521/xe");

Env= Environment: CreateEnvironment(Environment: OBJECT);

Conn= Env-> CreateConnection(Struser, Strpwd, Strconn_string);

If(NULL! = Conn)

Cout<"Conn success"<Endl;

Else

Cout<"Conn failed"<Endl;

String strsql("Select deptno, dname from dept");

Stmt= Conn-> CreateStatement(Strsql);

ResultSet* Rset= Stmt-> ExecuteQuery();

While(Rset-> Next()){

Intdeptno= Rset-> GetInt(1);

String dname= Rset-> GetString(2);

Cout<"Deptno ="<Deptno<", Dname ="<Dname<Endl;

}

Stmt-> CloseResultSet(Rset);

Conn-> TerminateStatement(Stmt);

Env-> TerminateConnection(Conn);

Environment: TerminateEnvironment(Env);

Return0;

}

(2) Compile and run:

[root@MyRHELtest]#g++-oconnclientconnclient.cpp-L/usr/lib/oracle/11.2/client64/lib-I/usr/include/oracle/11.2/client64/-locci-lclntsh/usr/lib64/libstdc++.so.6[root@MyRHELtest]#./connclientconnsuccessdeptno=10,dname=ACCOUNTINGdeptno=20,dname=RESEARCHdeptno=30,dname=SALESdeptno=40,dname=OPERATIONS

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.