开发者

Can't compile against OCILIB

I'm having trouble compiling some code against ocilib (libocilib.a) on version 3.9.0:

$ ls

libocilib.a ocilib.h test.c

$ gcc -o test -L. -locilib test.c

/tmp/cc4071VP.o: In function `main':

test.c:(.text+0x27): undefined reference to OCI_Initialize

test.c:(.text+0x64): undefined reference to OCI_ConnectionCreate

test.c:(.text+0x9d): undefined reference to OCI_StatementCreate

test.c:(.text+0xaf): undefined reference to OCI_ExecuteStmt

test.c:(.text+0xb8): undefined reference to OCI_GetResultset

test.c:(.text+0xcc): undefined reference to OCI_GetString

test.c:(.text+0xdd): undefined reference to OCI_FetchNext

test.c:(.text+0xe6): undefined reference to OCI_Cleanup

collect2: ld returned 1 exit status

Ok. In that case:

$ strings libocilib.a | grep OCI_Initialize

OCI_Initialize

OCI_Initialize

OCI_Initialize

OCI_Initialize

There was a solution to this problem answered by the man (vince) himself on another page, but it isn't working for me.

What DOES work is when I try to compile against an .so:

$ ls

libocilib.so* libocilib.so.3* libocilib.so.3.9.0* ocilib.h test.c

$ gcc -o test -L. -locilib test.c

$

The program runs as expected as well (after modifying LD_LIBRARY_PATH, of course!).

The solution mentioned earlier includes some defines -DOCI_IMPORT_LINKAGE and -DOCI_CHARSET_ANSI I've tried with both of these (even though the online docs say that DOCI_IMPORT_LINKAGE is only used while compiling the library itself. I had assumed that pertains more to the linki开发者_运维技巧ng of the actual oracle libs than it does ocilib. It was tried, none the less.

Speaking of which, if it helps to answer the question, I compiled the library to have runtime linking, having passed the --with-oracle-import=runtime flag into ./configure.

One more side note, something similar happens on Windows 32-bit. No problems with Windows 64. I can link and run a program against my own compiled libocilib.lib just fine.

Hopefully I've provided enough clues... anyone know what I'm doing wrong?

Thanks in advance help.


Have you tried linking it like this?

gcc -o test test.c -L. -locilib

At least in the past (I haven't done much C/C++ in a long time) the order of linking mattered. test.o would have references to OCI_Initialize and with libocilib.a after test.o, those would be satisfied. But if you linked the other way around those references would not be satisfied because the linker saw the OCI_Initialize symbol before it looked at test.o and so never realized it needed to keep a "pointer" to the symbol around when looking at test.o.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜