CentOS 6.6上搭建C++运行环境

前端之家收集整理的这篇文章主要介绍了CentOS 6.6上搭建C++运行环境前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



1、安装运行环境

#yuminstallgcc-c++

备注:此时会将gcc-c++和libstdc++-devel都安装上。

2、查看g++是否安装成功

[root@MyRHEL桌面] #g++-v

使用内建 specs。

目标:x86_64-redhat-linux

配置为:../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

线程模型:posix

gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)

3、测试

(1)测试C语言程序testc.c

#include<stdio.h>
int main()
{
printf ( "HelloC!\n" );
return 0;
}

运行:

#gcctestc.c-otestc
#./testc

(2)测试C++程序test.cpp

#include<iostream>
using namespace std;
main()
{
cout<< "ComeupandC++mesometime." ;
cout<<endl;
"Youwon'tregretit!" <<endl;
10;
#g++-otest1test.cpp
#./test1

4 安装OracleClient

主要安装oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpmoracle-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 配置

1)配置ld.so.conf文件,填入如下内容

#vi/etc/ld.so.conf
includeld.so.conf.d/*.conf
/usr/lib/oracle/11 .2 /client64/lib

2)配置/etc/hosts文件(此处填入Linux系统主机的IP地址和主机名称),填入如下内容

#vi/etc/hosts
127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4
::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6
192.168.48.128MyRHEL

6 测试与Oracle数据库连接

1)建立一个connclient.cpp文件,输入如下内容

[root@MyRHEL test]# vi connclient.cpp

#include<iostream>

#include<string>

#include<occi.h>

usingnamespacestd;

namespaceoracle::occiintmain()

{

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,strpwdstrconn_string if(NULL!=conn)

cout<<"conn success"<<endlelse

"conn Failed";

string strsql"select deptno,dname from dept" stmt=conn->createStatement(strsql ResultSet*rset=stmt->executeQuery();

while(rset->next()){

intdeptno=rset->getInt(1 string dname->getString2"deptno="<<deptno",dname="<<dname}

->closeResultSet->terminateStatement(stmt->terminateConnection(conn::terminateEnvironment(envreturn0 2)编译运行:

[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]#./connclient
connsuccess
deptno=10,dname=ACCOUNTING
deptno=20,dname=RESEARCH
deptno=30,dname=SALES
deptno=40,dname=OPERATIONS

猜你在找的CentOS相关文章