开发者

How to define where libs are loaded from

开发者 https://www.devze.com 2023-01-31 09:17 出处:网络
I am trying to compile omniORB on AIX 6.1 with gcc 4.2.0. The initialization does not work as it is picking up the non pthreaded library.

I am trying to compile omniORB on AIX 6.1 with gcc 4.2.0.

The initialization does not work as it is picking up the non pthreaded library.

If I set LIBPATH to /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/ omniNames will not work, as the streams interface gives an exception.

Setting the LIBPATH to /opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/pthread seems to work, but other non pthreaded programs will pick up the pthreaded lib which may cause problems...

The link looks like this:

g++开发者_运维技巧 -o omniNames -O2 -Wall -Wno-unused -fexceptions -Wl,-brtl -Wl,-blibpath:/lib:/usr/lib:/opt/dbx/omniORB-4/lib -L../../../lib -L../../../../lib omniNames.o NamingContext_i.o log.o omniNamesWin.o -lomniORB4-ar -lomnithread34 -lpthreads

How do I resolve this ??

Note that I have tried to change libpath using configure arguments but without success.


Launching via a wrapper script which set LIBPATH correctly is probably the easiest.

Then there is the RUNPATH/RPATH feature of ELF which allows to embded a search path for dynamic libraries in the executable; but I don't know if AIX implement it. It it does and is set with the same argument as for Linux and Solaris, -Wl,--enable-new-dtags -Wl,-R$(RUNPATH) for DT_RUNPATH, -Wl,--disable-new-dtags -Wl,-R$(RPATH) for DT_RPATH; you may want to test also simply -Wl,-R$(RPATH) (which will probably set the DT_RPATH).


Each OS uses its own unique set of environment variables to decide where to search for shared libraries.

Most UNIX like systems use LD_LIBRARY_PATH (but it varies).

I found that the most effective way to find which environment variable to use is to look at the man page for dlopen() on the platform you are building for.

Edited: also note that these variables act like the PATH environment variables, in that they are a list of paths that are ':' separated. So could you not set the environment like this:

# Using  tcsh syntax for setting environment. Your shell may very.
setenv LIBPATH "/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/:/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/pthread"


The AIX ld man page states:

   Note: If you specify a shared object, or an archive file containing a
   shared object, with an absolute or relative path name, instead of with
   the -lName flag, the path name is included in the import file ID string
   in the loader section of the output file. You can override this
   behavior with the -bnoipath option.

So, just specifying /my/path/to/libfoo.so instead of -lfoo should give you the behaviour you want.

0

精彩评论

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

关注公众号