如何搭建linux下c++开发环境
1个回答
展开全部
方法/步骤
1
1、下载
Linux 下的 Oracle Instant Client 有rpm包和zip包两种,下载任意一种即可,这里以下载的 zip
包为例,下载rpm包的安装见 Oracle Instant Client rpm包安装
instantclient-basic-linux.x64-11.2.0.3.0.zip
instantclient-sqlplus-linux.x64-11.2.0.3.0.zip
instantclient-sdk-linux.x64-11.2.0.3.0.zip
instantclient-precomp-linux.x64-11.2.0.3.0.zip
2、解压安装 unzip
instantclient-basic-linux.x64-11.2.0.3.0.zip unzip
instantclient-sqlplus-linux.x64-11.2.0.3.0.zip unzip
instantclient-sdk-linux.x64-11.2.0.3.0.zip unzip
instantclient-precomp-linux.x64-11.2.0.3.0.zip
文件被解压到目录instantclient_11_2下
3、创建数据库连接文件在instantclient_11_2目录下创建
network/admin目录,使用命令mkdir -p
network/admin,并在admin目录下创建tnsnames.ora文件,文件内容类似如下:XXX = (DESCRIPTION
= (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =
192.168.0.10)(PORT = 1521)) ) (CONNECT_DATA =
(SERVICE_NAME = orcl) ) )
4、配置环境变量 这里配置 root 用户环境变量:
~/.bash_profile export ORACLE_HOME=/oracle/instantclient_11_2
export PROC=$ORACLE_HOME/sdk export PATH=$PATH:$ORACLE_HOME:$PROC
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:$ORACLE_HOME export
LIBRARY_PATH=$LIBRARY_PATH:/usr/lib:$ORACLE_HOME
注意要配置LD_LIBRARY_PATH变量,sqlplus等程序运行时需要加载相应库,若不配置,则运行时会出现错误配置完毕后 source
~/.bash_profile
5、sqlplus测试[centos@localhost soft]$ sqlplus
/nologSQL*Plus: Release 11.2.0.1.0 Production on 星期二 1月 10 11:14:31
2012Copyright (c) 1982, 2009, Oracle. All rights reserved.SQL> conn
scott/tiger@XXX
已连接SQL>
6、proc测试
测试代码:
#include <stdio>
exec sql include sqlca;
int main(void) {
exec sql begin declare section;
char userpwd[30] = "scott/tiger@XXX";
char curdate[20] = {0};
exec sql end declare section;
exec sql connect:userpwd;
if(sqlca.sqlcode == 0) {
fprintf(stderr, "connect to database success!\n");
}
else {
fprintf(stderr, "connect to database failed! error:%s\n", sqlca.sqlerrm.sqlerrmc);
return -1;
}
exec sql select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') into:curdate from dual;
fprintf(stderr, "%s", curdate);
return 0;
}
1
1、下载
Linux 下的 Oracle Instant Client 有rpm包和zip包两种,下载任意一种即可,这里以下载的 zip
包为例,下载rpm包的安装见 Oracle Instant Client rpm包安装
instantclient-basic-linux.x64-11.2.0.3.0.zip
instantclient-sqlplus-linux.x64-11.2.0.3.0.zip
instantclient-sdk-linux.x64-11.2.0.3.0.zip
instantclient-precomp-linux.x64-11.2.0.3.0.zip
2、解压安装 unzip
instantclient-basic-linux.x64-11.2.0.3.0.zip unzip
instantclient-sqlplus-linux.x64-11.2.0.3.0.zip unzip
instantclient-sdk-linux.x64-11.2.0.3.0.zip unzip
instantclient-precomp-linux.x64-11.2.0.3.0.zip
文件被解压到目录instantclient_11_2下
3、创建数据库连接文件在instantclient_11_2目录下创建
network/admin目录,使用命令mkdir -p
network/admin,并在admin目录下创建tnsnames.ora文件,文件内容类似如下:XXX = (DESCRIPTION
= (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =
192.168.0.10)(PORT = 1521)) ) (CONNECT_DATA =
(SERVICE_NAME = orcl) ) )
4、配置环境变量 这里配置 root 用户环境变量:
~/.bash_profile export ORACLE_HOME=/oracle/instantclient_11_2
export PROC=$ORACLE_HOME/sdk export PATH=$PATH:$ORACLE_HOME:$PROC
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:$ORACLE_HOME export
LIBRARY_PATH=$LIBRARY_PATH:/usr/lib:$ORACLE_HOME
注意要配置LD_LIBRARY_PATH变量,sqlplus等程序运行时需要加载相应库,若不配置,则运行时会出现错误配置完毕后 source
~/.bash_profile
5、sqlplus测试[centos@localhost soft]$ sqlplus
/nologSQL*Plus: Release 11.2.0.1.0 Production on 星期二 1月 10 11:14:31
2012Copyright (c) 1982, 2009, Oracle. All rights reserved.SQL> conn
scott/tiger@XXX
已连接SQL>
6、proc测试
测试代码:
#include <stdio>
exec sql include sqlca;
int main(void) {
exec sql begin declare section;
char userpwd[30] = "scott/tiger@XXX";
char curdate[20] = {0};
exec sql end declare section;
exec sql connect:userpwd;
if(sqlca.sqlcode == 0) {
fprintf(stderr, "connect to database success!\n");
}
else {
fprintf(stderr, "connect to database failed! error:%s\n", sqlca.sqlerrm.sqlerrmc);
return -1;
}
exec sql select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') into:curdate from dual;
fprintf(stderr, "%s", curdate);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询