[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Thu Oct 19 20:05:02 2006 
Subject:pop-forum Re: nag libraries under Linux 
From:Waldek Hebisch 
Volume-ID: 

Anthony Worrall <Anthony.Worrall@reading.ac.uk> wrote:
> 
> Hi
> 
> I am trying to link in the the NAG libraries to pop11 under linux.
> 
> usiing the simple exload statments below gives a waring that the shared 
> library can not be opened,
> however sysopen will open it without any problems
> 
> 
> exload 'modnag'
>   ['/opt/NAG/fll3a21dgl/lib/libnag_nag.so']
>   (language C)
>   fo1ckf( A,B,C,N,P,M,Z,IZ,OPT,IFAIL) : void <- f01ckf_;
> endexload;
> 
> Warning: can't open shared object /opt/NAG/fll3a21dgl/lib
> ;;;     /libnag_nag.so (Success)
> ;;; Error: can't find value for symbol f01ckf_
>
<snip>
> vars dev=sysopen('/opt/NAG/fll3a21dgl/lib/libnag_nag.so',0,true);
> dev =>
> ** <device /opt/NAG/fll3a21dgl/lib/libnag_nag.so>
> sysclose(dev);
> 

The relevant code handling external load is in pop/src/extern_symbols.p:

#_ELSEIF DEF DLOPEN_FLAGS
        lvars _handle = _extern dlopen(Encode_sys(name,_nbuf), _:DLOPEN_FLAGS);
#_ELSE_ERROR
#_ENDIF
        if _nonzero(_handle) then Cons_extern_ptr(_handle) -> handle endif;
        returnif(handle);

        if shlib_error() ->> msg then
                '%can\'t open %S %S (%S)'
        else
                '%can\'t open %S %S (%M)'
        endif -> fast_subscrv(1, msvec);
        'Warning:' -> fast_subscrv(2, msvec);
        sys_pr_message(SHLIB_NAME, name, if msg then msg, 3 else 2 endif,
                msvec, nullstring, `W`)

So, you get warning if (and only if) dlopen call failed. The error message
'Success' is uniformative, but AFAIK if dlopen can not find file
the error message says it, so we may assume that dlopen finds the
library, but for some reason the library can not be loaded. One
possibility is that nag library is defective or incorrectly installed.
One simple test is to use ldd command to find out is all libraries
needed by nag library are present. For example, running ldd on
a toy shared library gives me:

$ ldd tstlib.so
        libg2c.so.0 => /usr/lib64/libg2c.so.0 (0x0000002a9568d000)
        libm.so.6 => /lib64/libm.so.6 (0x0000002a957b0000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000002a95909000)
        libc.so.6 => /lib64/libc.so.6 (0x0000002a95a14000)
        /lib64/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x000000552aaaa000)

So, you can see that tstlib.so is compiled by g77 (because it uses libg2c.so)
and needs also a few system libraries. 

One problem is when some of needed libraries can not be found. Another
is when the list of needed libraires is too short. In the second
case newer Poplog versions  try to work around the problem giving
RTLD_GLOBAL flag to dlopen (better solution is to re-link the
shared library giving correct list of dependencies). This Poplog
workaround only works if you have loaded all dependencies earlier.

Yet another possibility is that your Poplog has this workaround,
but the workaround is causing trouble.

I would first try to find out if nag library is working at all
(ldd command gives you a sanity check, better would be to use it
in another program).


-- 
                              Waldek Hebisch
hebisch@math.uni.wroc.pl