# Runtime errors with g95 + dynamic libraries



## nicecupoftea (Mar 6, 2006)

Hi,

I've been trying to compile and run some code using g95 and pgplot on my new desktop (Mac OS X 10.4.5) but I'm running into some weird (Tiger-specific?) problems. I started off using the pgplot that was already installed on my Mac (from Starlink, if that makes a difference) and g95 from Fink. I compiled the code with no trouble using

%g95 wpplot.f90 -L/local-star/lib -lpgplot

But when I ran it, I encountered this error:

dyld: lazy symbol binding failed: Symbol not found: _s_cat
   Referenced from: /local-star/lib/libpgplot.0.dylib
   Expected in: flat namespace

 dyld: Symbol not found: _s_cat
   Referenced from: /local-star/lib/libpgplot.0.dylib
   Expected in: flat namespace

 Trace/BPT trap

Then, remembering that I was always able to run pgplot downloaded from another source (scisoft) on my laptop (running 10.3.9), I downloaded it from there instead and installed it on my desktop. After trouble-free compilation, I got the following runtime error:

dyld: Library not loaded: /usr/local/lib/libpgplot.dylib
  Referenced from: /Users/rmason/data/Miche-BN-specpol/./a.out
  Reason: image not found
Trace/BPT trap

I really have no idea what to do. Anybody out there know what's going on and how I can fix it?? Thanks very much!


----------



## tomdkat (Mar 7, 2006)

nicecupoftea said:
			
		

> %g95 wpplot.f90 -L/local-star/lib -lpgplot
> 
> But when I ran it, I encountered this error:
> 
> ...


This means the "_s_cat" symbol wasn't found in libpgplot.0.dylib which means the wpplot.f90 file must be referencing a symbol it expects to be in a certain version of libpgplot.dylib.  So, make sure you've got the correct version of this library installed.



> Then, remembering that I was always able to run pgplot downloaded from another source (scisoft) on my laptop (running 10.3.9), I downloaded it from there instead and installed it on my desktop. After trouble-free compilation, I got the following runtime error:
> 
> dyld: Library not loaded: /usr/local/lib/libpgplot.dylib
> Referenced from: /Users/rmason/data/Miche-BN-specpol/./a.out
> ...


Ok, in the first set of output, libpgplot.dylib was located in /local-star/lib/.  The output above shows pgplot is looking for libpgplot.dylib in /usr/local/lib.

First, find where libpgplot.dylib is actually located:

$ ls -l /usr/local/lib/libpgplot*
$ ls -l /local-star/lib/libpgplot*

If you find libpglot in BOTH directories, you will have to figure out which one to use and build pgplot to use that library.  Hopefully, one of them contants the "_s_cat" symbol.  You *might* be able to verify that using a command like this:

$ nm /usr/local/lib/libpgplot.dylib | grep "_s_cat"

See if you get any output.  Replace the "/path/to/libpgplot.dylib" with the appropriate locations, based on the "ls" commands above.

If nothing else, this is something to try until someone more knowledgable responds.  

Peace...


----------



## macbri (Mar 24, 2006)

nicecupoftea said:
			
		

> %g95 wpplot.f90 -L/local-star/lib -lpgplot
> 
> But when I ran it, I encountered this error:
> 
> ...



I've seen this on Linux too, whenever I compile something in Fortran that needs certain system library functions.  Try recomiling with:

%g95 wpplot.f90 -L/local-star/lib -lpgplot -lg2c

(I don't have my powerbook with me today to check, but I *believe* libg2c comes as part of the g77/g95 package, be that from Fink, Darwinports or whatever).



			
				nicecupoftea said:
			
		

> Then, remembering that I was always able to run pgplot downloaded from another source (scisoft) on my laptop (running 10.3.9), I downloaded it from there instead and installed it on my desktop. After trouble-free compilation, I got the following runtime error:
> 
> dyld: Library not loaded: /usr/local/lib/libpgplot.dylib
> Referenced from: /Users/rmason/data/Miche-BN-specpol/./a.out
> ...



This is because your downloaded version of pgplot is looking for libpgplot.dylib in a different location (/usr/local/lib).  Set your DYLD_LIBRARY_PATH to look in /local-star/lib/ as follows:

(if you use /bin/tcsh):  setenv DYLD_LIBRARY_PATH /local-star/lib
(if you use /bin/bash): export DYLD_LIBRARY_PATH=/local-star/lib

Then try running your downloaded version of pgplot again.


----------



## tomdkat (Mar 27, 2006)

macbri said:
			
		

> This is because your downloaded version of pgplot is looking for libpgplot.dylib in a different location (/usr/local/lib).  Set your DYLD_LIBRARY_PATH to look in /local-star/lib/ as follows:
> 
> (if you use /bin/tcsh):  setenv DYLD_LIBRARY_PATH /local-star/lib
> (if you use /bin/bash): export DYLD_LIBRARY_PATH=/local-star/lib


I agree with this except I wouold change the path setting to:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/local-star/lib (if using bash)
setenv DYLD_LIBRARY_PATH "/local-star/lib:$DYLD_LIBRARY_PATH" (if using tcsh)

That way, DYLID_LIBRARY_PATH won't be accidentally clobbered.

Peace...


----------



## nicecupoftea (Apr 14, 2006)

Hi,

so I finally got my programme running (been travelling and using the trusty old laptop for a while). As you all pointed out, it was looking in the wrong place for some of these dynamic libraries. The SETENV command that you suggested didn't seem to point it in the right direction but I got round that by copying the necessary libraries to /usr/local/lib abd that seems to have fixed everything.

Thanks very much for your help!


----------

