1.首先下载ocilib到自己目录

github:https://github.com/vrogier/ocilib

2.在下载instantclient 11.2.2的文件:

instantclient-basic-linux-11.2.0.3.0.zip

instantclient-sdk-linux-11.2.0.3.0.zip

都解压生成在

/usr/local/instantclient_12_2

3.配置环境变量

export ORACLE_HOME=/usr/local/instantclient_12_2

export PATH=$ORACLE_HOME:$PATH

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

#export TNS_ADMIN=$ORACLE_HOME/network/admin

#export NLS_LANG="Simplified Chinese_china".ZHS16GBK

4.

./configure

a.出错找不到include,修改configure

大约在line

12113 # find out the Oracle public OCI headers path
12114 ac_headers_path=$ac_oracle_home/sdk/include
12115 if test "$ac_headers_path" = NO; then
12116 if test "$ac_oracle_home" != NO; then
12117 test_include_path=$ac_oracle_home/rdbms/public
12118 if test -d "$test_include_path"; then
12119 ac_headers_path=$test_include_path
12120 else
12121 test_include_path=$ac_oracle_home/rdbms/demo
12122 if test -d "$test_include_path"; then
12123  ac_headers_path=$test_include_path
12125 fi
12126 fi
12127 fi
12128 fi

b.“aclocal-1.15”在你的系统上缺少“编译时的警告

运行前./configure尝试运行autoreconf -f -i。autoreconf程序根据需要自动运行autoheader,aclocal,automake,autopoint和libtoolize。

具体见:http://stackoverflow.com/questions/33278928/how-to-overcome-aclocal-1-15-is-missing-on-your-system-warning-when-compilin

make

需要root

make install

 

测试实例:

#include <stdio.h>
#include <iostream>
#include <list>
#include <memory>
#include "ocilib.h"
using namespace std; int main(int argc, char *argv[])
{
OCI_Connection* cn;
OCI_Statement* st;
OCI_Resultset* rs; OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT); cn = OCI_ConnectionCreate("//192.168.52.129/ORCL", "system", "oracle", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn); OCI_ExecuteStmt(st, "SELECT * from \"t_stu\""); rs = OCI_GetResultset(st); while (OCI_FetchNext(rs))
{
printf("%i - %s\n", OCI_GetInt(rs, ), OCI_GetString(rs,));
} OCI_Cleanup(); return EXIT_SUCCESS;
}

export ORACLE_HOME=/usr/local/instantclient_12_2
export PATH=$ORACLE_HOME:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
g++ main.cpp -I/usr/local/ocilib/include -L/usr/local/ocilib -locilib

提示:

这里使用静态库

g++ -g -std=c++11  test_oracle.cpp file.cpp -o process  -I/usr/local/ocilib/include  -L/usr/local/ocilib -L/usr/local/instantclient_12_2 -lclntsh -locilib -lrt -lpthread

最新文章

  1. 初始通过 FastClick.notNeeded 方法判断是否需要做后续相关处理
  2. Verify Preorder/Inorder/Postorder Sequence in Binary Search Tree
  3. PHP Header下载文件在IE文件名中文乱码问题
  4. RESTful Webservice (一) 概念
  5. web.xml文件中配置ShallowEtagHeaderFilter需注意的问题
  6. Scut 上线后遇到的问题
  7. 从c#基础到java基础的学习的感悟
  8. 修改MyEclipse字体大小及颜色
  9. tensorflow中tf.ConfigProto()用法解释
  10. StringUtils方法介绍
  11. Structs复习 Structs标签
  12. 对va_list; va_start ; va_end ;vsprintf理解(转)
  13. 【HAOI2014】贴海报
  14. 【WPF】当 ItemsSource 正在使用时操作无效。改用 ItemsControl.ItemsSource 访问和修改元素
  15. 【go】用Golang的 http 包建立 Web 服务器
  16. Qt使用QNetworkAccessManager实现Http操作
  17. 使用Navicat for MySQL
  18. mysql数据库将表移动到新数据库,或者说更改数据库名字
  19. python+appuim 处理系统权限弹窗
  20. 团队项目-第十次scrum 会议

热门文章

  1. View的滑动原理和多种滑动方法
  2. 零开始Android逆向教程(一)——初探Android逆向
  3. 使用 WPF 生成图形
  4. SPSS正交设计的操作
  5. 让footer始终待在页面底部
  6. spring JdbcTemplate最基本的使用
  7. js创建svg元素的方法
  8. 在Linux系统下进入MySql数据库进行操作
  9. 【洛谷P1827】【USACO】 美国血统 American Heritage 由二叉树两个序列求第三个序列
  10. Leetcode665.Non-decreasing Array非递减数组