1. Installation and operating environment
# yum Install gcc-c++
Note: Both gcc-c++ and Libstdc++-devel will be installed at this time.
2. See if the g++ is installed successfully
[[Email protected] Desktop]# g++-V
Use built-in specs.
Target: X86_64-redhat-linux
Configured as:.. /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
Threading Model: POSIX
GCC version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
3. Testing
(1) Test C language Program TESTC.C
#include <stdio.h>
int main ()
{
printf ("Hello c!\n");
return 0;
}
Run:
# gcc Testc.c-o TESTC
#./TESTC
(2) Test C + + program 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;
}
Run:
# g++-O test1 test.cpp
#./test1
4 Installing OracleClient
Mainly installs 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 content:
# vi/etc/ld.so.conf
Include ld.so.conf.d/*.conf
/usr/lib/oracle/11.2/client64/lib
(2) Configure the/etc/hosts file (which fills in the IP address and host name of the Linux system host) and fill in the following contents:
# 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 Testing the connection to the Oracle database
(1) Create a connclient.cpp file and enter the following:
[Email protected] 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:
[Email protected] test]# g++-o connclient connclient.cpp-l/usr/lib/oracle/11.2/client64/lib-i/usr/include/oracle/1 1.2/client64/-locci-lclntsh/usr/lib64/libstdc++.so.6
[Email protected] test]#./connclient
Conn Success
Deptno=10,dname=accounting
Deptno=20,dname=research
Deptno=30,dname=sales
Deptno=40,dname=operations
See Oracle Feature page for more information on Oracle HTTP://WWW.LINUXIDC.COM/TOPICNEWS.ASPX?TID=12
Install g++ in Centoos and connect to Oracle database