0

I have a C executable which depends on libdb2.a. Yet, when the executable is called, the following error popped up:

exec(): 0509-036 Cannot load program /my/path/my_c_exe because of the following errors:
        0509-150   Dependent module libdb2.a(shr.o) could not be loaded.
        0509-022 Cannot load module libdb2.a(shr.o).
        0509-026 System error: A file or directory in the path name does not exist.

Later, it is found that I should add the following env setting in the file .profile in my home directory:

LIBPATH=/db2/v84bc/sqllib/lib64
export LIBPATH

Yes, the issue is resolved. But I am still bewildered at the original error because the static library libdb2.a should be built into the c executable /my/path/my_c_exe in compile time. The executable should not have been looking for the static library it depends on in run time, should it? If db2 is a shared object, I can see the rationale. But for a static library, the error is beyond my understanding.

Any hints on the cause of this error? Or, though libdb2.a is named as a static library, it actually is a shared object? How to determine whether a library is a static one or a shared object, other than looking at the suffix (.a or .so)?

Qiang Xu
  • 4,353
  • 8
  • 36
  • 45

1 Answers1

1

Your assumptions about the suffix .a indicating a static library is incorrect. By convention .a is the suffix for shared libraries, which can contain shared and static objects, both having the suffix .o. Whether an object is shared or static is indicated in its XCOFF header.

More info in the manual.

mustaccio
  • 18,234
  • 16
  • 48
  • 57
  • Thank you for the answer. Do you know how to check XCOFF header of `libdb2.a`? – Qiang Xu Aug 26 '14 at 16:21
  • 1
    Did you have a chance to review the link I included in my answer? – mustaccio Aug 26 '14 at 16:48
  • Thanks for your reminding, mustaccio. I did check the link in your answer, but not carefully enough. Now I re-examined the article and found the command to check out the library's header is `dump -ov`. – Qiang Xu Aug 26 '14 at 19:18