ocilib linux编译安装

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 -iautoreconf程序根据需要自动运行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, 1), OCI_GetString(rs,2));
    }

    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

posted @ 2017-04-17 18:56  略加思索的河马  阅读(1551)  评论(0编辑  收藏  举报