【问题标题】:Problems Compiling OCILIB OCI Wrapper Library编译 OCILIB OCI Wrapper 库的问题
【发布时间】:2010-12-20 14:42:36
【问题描述】:

我正在尝试在ocilib3.8.1/demo 中编译演示。成功安装ocilib库后,我再编译demo source conn.c如下:

#include "ocilib.h"

int main(void)
{
    OCI_Connection *cn;

    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);

    printf("Server major    version : %i\n",   OCI_GetServerMajorVersion(cn));
    printf("Server minor    version : %i\n",   OCI_GetServerMinorVersion(cn));
    printf("Server revision version : %i\n\n", OCI_GetServerRevisionVersion(cn));
    printf("Connection      version : %i\n\n", OCI_GetVersionConnection(cn));

    OCI_Cleanup();

    return EXIT_SUCCESS;
}

使用 gcc 编译:

$gcc -Wall conn.c -o conn.o -I/usr/local/include \
    -DOCI_IMPORT_LINKAGE -DOCI_CHARSET_ANSI

错误:

$ gcc -Wall conn.c -o conn.o -I/usr/local/include \
    -DOCI_IMPORT_LINKAGE -DOCI_CHARSET_ANSI
/tmp/ccMgFQri.o: In function `main':
conn.c:(.text+0x26): undefined reference to `OCI_Initialize'
conn.c:(.text+0x4f): undefined reference to `OCI_ConnectionCreate'
conn.c:(.text+0x63): undefined reference to `OCI_GetServerMajorVersion'
conn.c:(.text+0x82): undefined reference to `OCI_GetServerMinorVersion'
conn.c:(.text+0xa1): undefined reference to `OCI_GetServerRevisionVersion'
conn.c:(.text+0xc0): undefined reference to `OCI_GetVersionConnection'
conn.c:(.text+0xd6): undefined reference to `OCI_Cleanup'
collect2: ld returned 1 exit status

我使用的是 redhat el5,gcc 版本 3.4.6 20060404 (Red Hat 3.4.6-4),即时客户端版本 10.2.0.5.0。

感谢您的帮助。我是 linux 编程的新手..

【问题讨论】:

    标签: c oracle oracle-call-interface


    【解决方案1】:

    你必须链接到 ocilib !

    在命令行中添加“-locilib”:)

    【讨论】:

    • 可能还需要-L 到(我猜)/usr/local/lib 才能找到库。并且不需要-o conn.o 参数?
    • gcc -DOCI_IMPORT_LINKAGE -DOCI_CHARSET_ANSI -L$ORACLE_HOME/lib -lclntsh -L/usr/local/lib -locilib conn.c -o conn
    猜你喜欢
    • 2011-08-01
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多