0

I'm trying to use the ncurses library on AIX 7.1 to make use of panels which aren't included in the curses library that is standard on AIX. I have the ncurses library installed. The compile,link, and execute work fine with: xlc ngoodbye.c -lncurses The actual ncurses library is libncurses.a, which I understand is a static library. However, when I move the executable to another AIX host and execute I get: Dependent module libncurses.a(libncurses.so.5) could not be loaded. Could not load module libncurses.a(libncurses.so.5). System error: No such file or directory.

How can I link the ncurses library so that the program will execute on other hosts where the ncurses library isn't installed? Note I'm using xlc on AIX, not gcc. I've tried -bstatic but get link errors at compile time. Note that I'm not a developer so my experience in this area is limited. Thanks.

2 Answers2

0

Normally ".a" does mean a static library. However, in adapting the initial report (in 2008) describing the AIX 5 shared library configuration there was some miscommunication and ".a" was used for both static and shared libraries. That was finally corrected last year (see changelog).

AIX 4, by the way, used a much more complicated scheme, so shared libraries for ncurses were first implemented on AIX 5.

Packagers prefer shared libraries. So what you have is a shared library named libncurses.a (legal, but not conventional). This is not created with the archiver ar, but using the loader ld. To see that they are different, you can try

ar tv libncurses.a

(with the appropriate directory). Likely ar will say something like

ar: 0707-108 File libncurses.a is not an archive file.

while file may give a more informative message:

libncurses.a: executable (RISC System/6000) or object module not stripped

You can however build ncurses from source. In that case (no matter what version), the default builds static libraries. You need not install those into the system area, but can configure ncurses using the --prefix option to install into a different directory.

As suggested in another answer, there is a workaround using the -bdynamic and -bstatic options of AIX's ld (loader), e.g., changing

xlc -o foo foo.c -lncurses

to

xlc -o foo foo.c -bstatic -lncurses -ldynamic

However, this is partly dependent upon the loader's search path and the name of the archive. If the archive is named libncurses.a, the command works as given. If it is named libncurses.so (as in current sources), then this command is needed to link against the shared library:

xlc -o foo foo.c -brtl -lncurses

But this command (which one might suppose to provide the static linkage using the libncurses.so file) does not succeed:

xlc -o foo foo.c -brtl -bstatic -lncurses -bdynamic
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • 1
    In traditional unix, `.a` suffix is for archive which is produced by ar. It is neither static nor shared but a group of files -- often object files not required to be object files. The object files can be shared or static. They can also be different bit sizes with 32 bit and 64 bit object files within the same archive. You can dump out libc.a for example and find all four types within the same archive. – pedz Apr 16 '15 at 17:54
0

Both static and shared libraries in AIX are built as position independent (PIC). So even a "shared" library can be statically bound to an executable. You were on the right track with -bstatic, you just need to switch back to dynamic binding for the rest of the libraries you're linking to.

So try this for your final link:

xlc -o myexe myexe.o <other objects as needed> -bstatic -lncurses -bdynamic -lm <and other other libraries as needed>

I do this all the time to make sure that my production environment matches my development one.

CoreyStup
  • 1,488
  • 13
  • 14
  • But if the library is dynamic, the switch is not effective. – Thomas Dickey Apr 16 '15 at 22:57
  • This answer worked for me..ie: xlc myexe.c -bstatic -lncurses -bdynamic. Thanks very much for the quick reply. This is my first question here so evidently not able to upvote answers yet. – Jim Fletcher Apr 17 '15 at 00:44
  • 1
    It works this way on AIX, @ThomasDickey. It truly does bind the library into the executable the same way a static library/object file would. AIX works differently than most other unixes in this regard. – CoreyStup Apr 17 '15 at 01:39