QMG
QMG

Reputation: 749

ld failed to link

Dear All, Here is my command to link libraries and generate an exe:

ld -o readgfile  readg_x.o MedLib_x.o cdrsort.o mtcprc.o encoder.o mtcbuil.o dbtprc.o dbtbuil.o  DFMLIB_x.o Dyn_SQL_x.o /home/med/src/api/libnapi.a  /home/med/src/api/libtabs.a $ORACLE_HOME/lib/libclntsh.so

But when I run the command it failed to locate function used in readg_x.o from file archived in libtabs.a. Here are error like :

readg_x.o: In function `main':
/home/med/src/readg/readg_x.c:565: undefined reference to `options'
/home/med/src/readg/readg_x.c:570: undefined reference to `oraconnect'
/home/med/src/readg/readg_x.c:591: undefined reference to `oracommit'

Upvotes: 1

Views: 1879

Answers (2)

Employed Russian
Employed Russian

Reputation: 213375

You have two problems:

  1. You are trying to build an executable with ld. Once you manage to actually link it, the resulting executable will crash at startup, because you are not properly linking in the C startup (crt0.o). On UNIX/Linux, one should never use ld to link anything (with the rare exception of linking OS kernel or a bootloader). You should always use compiler driver instead, like this: gcc -o readgfile readg_x.o MedLib_x.o ...
  2. Even though you have claimed that oraconnect etc. are defined in libtabs.a, they are not (or at least they are not defined as global symbols). Without output from readelf -s libtabs.a | grep oraconnect, it is hard to tell exactly what's happening, but your assertion that the symbols are defined in that library is definitely false.

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328536

The error means the library libtabs.a doesn't contain what you think. You can use tools like objdump to list all symbols defined in a library to make sure what you expect is what really is.

Upvotes: 1

Related Questions