Problems Compiling OCILIB OCI Wrapper Library

雨燕双飞 提交于 2019-12-08 11:04:16

问题


I'm trying to compile demo in ocilib3.8.1/demo. After successfully installing the ocilib library, I then compile demo source conn.c below :

#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;
}

Compile using gcc :

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

Error :

$ 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

I'm using redhat el5, gcc version 3.4.6 20060404 (Red Hat 3.4.6-4), instant client Release 10.2.0.5.0.

Thanks for help. I'm newbies in linux programming ..


回答1:


you have to link against ocilib !

add "-locilib" to the command line :)



来源:https://stackoverflow.com/questions/4490636/problems-compiling-ocilib-oci-wrapper-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!