编译OCILIB OCI包装库的问题

时间:2010-12-20 14:42:36

标签: c oracle oci

我正在尝试在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编程的新手..

1 个答案:

答案 0 :(得分:3)

你必须链接到ocilib!

将“-locilib”添加到命令行:)