zoukankan      html  css  js  c++  java
  • 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
    ", 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

  • 相关阅读:
    JAVA中handleEvent和action的区别
    Hessian的使用以及理解
    Java基础中的RMI介绍与使用
    Callable与Runable接口 submit与execute区别
    XXL-JOB原理--定时任务框架简介(一)
    11.并发包阻塞队列之LinkedBlockingQueue
    并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法
    正确实现用spring扫描自定义的annotation
    自贡进入“刷脸卡”时代 人脸识别支付“黑科技”现身自流井老街
    谷歌最新研究:量子计算机能在8小时内破解2048位RSA加密
  • 原文地址:https://www.cnblogs.com/kaishan1990/p/6724301.html
Copyright © 2011-2022 走看看