CentOS 6.6 build C++ runtime environment


1, the installation environment
# yum install gcc-c++
Note: both gcc-c++ and libstdc++-devel will be installed at this time.
2, see g++ whether the installation was successful
[Root@MyRHEL desktop]# g++-v
Using built-in specs.
Aim: x86_64-RedHat-Linux
Configure:.. /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-languages=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 c program testc.c
#include<stdio.h>
int main()
{
printf(“Hello C!\n”);
return 0;
}
Running:
# gcc testc.c -o testc
# ./testc
(2) the C++ test program named test.cpp
#include <iostream>
using namespace std;
int main()
{
cout << “Come up and C++ me some time.”;
cout << endl;
cout << “You won’t regret it!” << endl;
return 10;
}
Running:
# g++ -o test1 test.cpp
# ./test1
4 install the OracleClient
Mainly installed 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 -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
# rpm –ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
5 configuration
(1) configure the LD.so.conf file, fill in the following:
# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/lib/oracle/11.2/client64/lib
(2) configure the/etc/hosts file (here fill in IP address and host name of the host Linux system), fill in the following:
# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.48.128 MyRHEL
6 test with Oracle database connections
(1) create a connclient.cpp file, enter the following:

 

[root@MyRHEL test]# vi connclient.cpp

 

#include<iostream>

#include<string>

#include<occi.h>

using namespace std;

using namespace oracle::occi;

int main()

{

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()){

int deptno = 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@MyRHEL test]# g++ -o connclient  connclient.cpp -L /usr/lib/oracle/11.2/client64/lib  -I /usr/include/oracle/11.2/client64/  -locci  -lclntsh  /usr/lib64/libstdc++.so.6
[root@MyRHEL test]# ./connclient
conn success
deptno=10,dname=ACCOUNTING
deptno=20,dname=RESEARCH
deptno=30,dname=SALES
deptno=40,dname=OPERATIONS