DISLIN with GFortran on Raspberry Pi with Raspbian

391 views
Skip to first unread message

John Wasilewski

unread,
Apr 23, 2016, 4:27:11 AM4/23/16
to dislin-users
I can't work out how to build GFortran projects under Raspbian, when calling DISLIN routines.
If anyone could help, I'd be very grateful.
I have been trying to discover how to do it by attempting to build an executable from the DISLIN F90 example, exa_f90.f90

I have GFortran successfully installed, and working properly.
I have installed DISLIN using the INSTALL script.
I put it in /usr/local/dislin
I am using Simply Fortran as my IDE.  This works properly.

I have compiled dislin.mod from dislin.f90, to make sure that dislin.mod has been compiled with the same version of GFortran as I am using for my own source files.  I did this with,
sudo gfortran -c dislin.f90

I am using the linker to load dislin.mod together with my object files.
I am expecting to need also to link libdislin.a .

When I try to build an executable using
 - my object files
 - the version of dislin.mod that I have compiled with the same compiler version
 - libdislin.a ,

I get shedloads of undefined references.

I've tried with
 - my object files
 - the version of dislin.mod as above
 - dislin-10.6.a

..and with
 - my object files
 - the version of dislin.mod as above
 - libdislin.so .

None of these works.

I've run the following commands:
 -
sudo apt-get install libmotif4
sudo apt-get install libmotif4* libmotif-dev
sudo apt-get install xfonts-75dpi sudo apt-get install xfonts-100dpi

..and I then tried again to build an executable by all the same methods as before.

The IDE I am using is Simply Fortran.
When making each build attempt, I have tried in two ways.  One is by adding both DISLIN files directly to teh project.  Yje other is by specifying these Project options :
   Fortran compiler > -I/usr/local/dislin/gf
   Linker                >  /usr/local/dislin/libdislin.a

By all of these attempts, I just can't get my GFortran projects that USE DISLIN, to work.

CAN ANYONE HELP?
---
John Wasilewski


Rauthe-Schöch, Armin

unread,
Apr 23, 2016, 9:02:36 AM4/23/16
to dislin...@googlegroups.com
Dear John,

can you track in your IDE how the GFortran compiler is called, i.e. with which options ? If I want to compile a DISLIN  program with GFortran on OpenSuSE linux, the following two calls do the trick:

# Compiling
gfortran -c test_dislin.f90 -I/usr/local/dislin/gf
# Linking
gfortran -o test_dislin test_dislin.o -L/usr/local/dislin/gf -ldislin

Hope that helps !

Armin


--
Dr. Armin Rauthe-Schöch
Max Planck Institute of Chemistry
Air chemistry department
Hahn-Meitner-Weg 1
D-55128 Mainz
Germany
Tel. +49-(0)6131-305-4123

From: dislin...@googlegroups.com [dislin...@googlegroups.com] on behalf of John Wasilewski [jo...@wasilewski.co.uk]
Sent: Saturday, April 23, 2016 10:27
To: dislin-users
Subject: DISLIN with GFortran on Raspberry Pi with Raspbian

--
You received this message because you are subscribed to the Google Groups "dislin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dislin-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Wasilewski

unread,
Apr 23, 2016, 1:41:13 PM4/23/16
to dislin-users
Dear Armin,

Thank you very much for trying to help me.

I TRIED setting Simply Fortran project options to these settings:
  Fortran :  -I/usr/local/dislin/gf
  Link      :  -L/usr/local/dislin/gf -ldislin
and no luck.

Just in case I was not understanding the Simply Fortran settings, I then tried compiling and linking from the command line.

FIRST, 

I tried the same commands as you mentioned (but with my pathnames/filenames): 

gfortran -c /usr/local/dislin/examples/exa_f90.f90 -I/usr/local/dislin/gf 

gfortran -o exa_f90 /usr/local/dislin/examples/exa_f90.o -L/usr/local/dislin/gf -ldislin

This gave an error message about being unable to find the dislin file.

SECOND

I tried compiling and linking like this:
gfortran -c /usr/local/dislin/examples/exa_f90.f90 -I/usr/local/dislin/gf
This worked, and produced a .o object file, called exa_f90.o.

I then tried linking with each of these in turn:
gfortran -o exa_f90 exa_f90.o /usr/local/dislin/dislin
gfortran -o exa_f90 exa_f90.o /usr/local/dislin/dislin.a
gfortran -o exa_f90 exa_f90.o /usr/local/dislin/libdislin.a
gfortran -o exa_f90 exa_f90.o /usr/local/dislin/libdislin
gfortran -o exa_f90 exa_f90.o /usr/local/dislin/libdislin.so
gfortran -o exa_f90 exa_f90.o /usr/local/dislin/lib/dislin_d-10.6.a

These all failed.  Either they gave an error about the library file not being found, or they produced a list a mile long, of unsatisfied references.

SO frustrating!

--- 

John


Rauthe-Schöch, Armin

unread,
Apr 23, 2016, 1:48:11 PM4/23/16
to dislin...@googlegroups.com
Dear John,

so compiling works fine. That's the first step. Now I would suggest to try this command for linking:

gfortran -o exa_f90 /usr/local/dislin/examples/exa_f90.o -L/usr/local/dislin/ -I/usr/local/dislin/gf -ldislin

Does it still give you error messages about not being able to find the dislin file ?


Cheers,

Armin


--
Dr. Armin Rauthe-Schöch
Max Planck Institute of Chemistry
Air chemistry department
Hahn-Meitner-Weg 1
D-55128 Mainz
Germany
Tel. +49-(0)6131-305-4123
Sent: Saturday, April 23, 2016 19:41
To: dislin-users
Subject: Re: DISLIN with GFortran on Raspberry Pi with Raspbian

Helmut Michels

unread,
Apr 23, 2016, 1:49:12 PM4/23/16
to dislin-users
Dear John,

please try the link command:
   gfortran -o exa_f90 /usr/local/dislin/examples/exa_f90.o -L/usr/local/dislin -ldislin  

The library libdislin.so is located in /usr/local/dislin, not in /usr/local/dislin/gf. The subdirectoy gf contains just the
module file dislin.mod, which is needed for compiling, but not for linking.

Best regards,

Helmut

John Wasilewski

unread,
Apr 23, 2016, 3:41:00 PM4/23/16
to dislin-users
Dear Helmut,

You seem to have infinite patience with so many people like having such basic problems, so I appreciate very much your help.  

Using the object file exa_f90.o that I had successfully compiled earlier, I tried the command you advised, with the result shown below (output abridged).  
It seems that the link is failing to find essential parts of dislin.

sudo gfortran -o exa_f90 exa_f90.o -L/usr/local/dislin/ldislin
exa_f90.o: In function `exa_0_':
exa_f90.f90:(.text+0x38): undefined reference to `metafl_'
exa_f90.f90:(.text+0x44): undefined reference to `setpag_'
exa_f90.o: In function `exa_14_':
exa_f90.f90:(.text+0x2d4): undefined reference to `disini_'
exa_f90.f90:(.text+0x2d8): undefined reference to `pagera_'
exa_f90.f90:(.text+0x2e8): undefined reference to `setvlt_'
exa_f90.f90:(.text+0x2fc): undefined reference to `height_'
exa_f90.f90:(.text+0x37c): undefined reference to `point_'
exa_f90.f90:(.text+0x3a0): undefined reference to `nlnumb_'
exa_f90.f90:(.text+0x3ac): undefined reference to `setclr_'
exa_f90.f90:(.text+0x3ec): undefined reference to `number_'
exa_f90.f90:(.text+0x454): undefined reference to `disfin_'
exa_f90.o: In function `exa_13_':
exa_f90.f90:(.text+0x49c): undefined reference to `disini_'
exa_f90.f90:(.text+0x4a0): undefined reference to `complx_'
:
:
:
:
exa_f90.f90:(.text+0x4b58): undefined reference to `title_'
exa_f90.f90:(.text+0x4b64): undefined reference to `color_'
exa_f90.f90:(.text+0x4b7c): undefined reference to `curve_'
exa_f90.f90:(.text+0x4b88): undefined reference to `color_'
exa_f90.f90:(.text+0x4ba4): undefined reference to `curve_'
exa_f90.f90:(.text+0x4bb0): undefined reference to `color_'
exa_f90.f90:(.text+0x4bb4): undefined reference to `dash_'
exa_f90.f90:(.text+0x4bb8): undefined reference to `xaxgit_'
exa_f90.f90:(.text+0x4bbc): undefined reference to `disfin_'
collect2: error: ld returned 1 exit status

--- 
John

John Wasilewski

unread,
Apr 23, 2016, 4:14:46 PM4/23/16
to dislin...@googlegroups.com
Although this command did not work, 
sudo gfortran -o exa_f90 exa_f90.o -L/usr/local/dislin/ldislin

...this one (thank you, Armin!) seems as if it HAS worked, though:
gfortran -o exa_f90 exa_f90.o -L/usr/local/dislin/ -I/usr/local/dislin/gf -ldislin

At least, I think it has, because it has resulted in no error message (in fact, no output at all from gfortran), and I have found a new file in the current directory, exa_f90,  47.2kB (48,320 bytes) with attributes rwx .

When I try to run it, though, by typing ./exa_f90, I receive an error message,
./exa_f90: error while loading shared libraries: libdislin.so.10: cannot open shared object file: No such file or directory.
Does that mean that, under Linux, compiled executables have to have access to library object  files?

I copied libdislin.so.10  into the same directory as my exa_f90 executable and then tried to run it again, but the result was the same.  I am beginning to sense that this must covered in the manual, but I don't remember seeing it there.
--- 
John


Rauthe-Schöch, Armin

unread,
Apr 24, 2016, 7:48:32 AM4/24/16
to dislin...@googlegroups.com
Hi John,

I agree with your analysis that the linking worked.

It is strange however that you cannot run the program because the linking worked and the OS knows which library it is looking for. I have two ideas:

1) Can you run the command "ldd exa_f90" ? It should give a long list of libraries similar to what I get for a (different) dislin program compiled with GFortran:
        linux-vdso.so.1 =>  (0x00007fff4f3ee000)
        libdislin.so.10 => /usr/lib64/libdislin.so.10 (0x00007f9814fa6000)
        libgfortran.so.3 => /usr/lib64/libgfortran.so.3 (0x00007f9814cbf000)
        libm.so.6 =>        linux-vdso.so.1 =>  (0x00007fff4f3ee000)
        libdislin.so.10 => /usr/lib64/libdislin.so.10 (0x00007f9814fa6000)
        libgfortran.so.3 => /usr/lib64/libgfortran.so.3 (0x00007f9814cbf000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f9814a68000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9814852000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f98144e5000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f98142c8000)
        libGL.so.1 => /usr/lib64/xorg/libGL.so.1 (0x00007f9815376000)
        libXm.so.4 => /usr/lib64/libXm.so.4 (0x00007f9813df7000)
        libXt.so.6 => /usr/lib64/libXt.so.6 (0x00007f9813b90000)
        libX11.so.6 => /usr/lib64/libX11.so.6 (0x00007f981384d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f981531a000)
        libXext.so.6 => /usr/lib64/libXext.so.6 (0x00007f981363a000)
 /lib64/libm.so.6 (0x00007f9814a68000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9814852000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f98144e5000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f98142c8000)
        libGL.so.1 => /usr/lib64/xorg/libGL.so.1 (0x00007f9815376000)
        libXm.so.4 => /usr/lib64/libXm.so.4 (0x00007f9813df7000)
        libXt.so.6 => /usr/lib64/libXt.so.6 (0x00007f9813b90000)
        libX11.so.6 => /usr/lib64/libX11.so.6 (0x00007f981384d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f981531a000)
        libXext.so.6 => /usr/lib64/libXext.so.6 (0x00007f981363a000)
...
...

I would expect that this will indicate that the OS cannot find libdislin.so.


2) Did you follow all installation instructions in /usr/local/dislin/README ? Especially

f) To make DISLIN available for general use, write the following com-
   mands to your .profile or to /etc/profile

                    DISLIN=/usr/local/dislin/    # or wherever your DISLIN distribution is to be found
                    export DISLIN  
                    PATH=${PATH}:${DISLIN}/bin

                    LD_LIBRARY_PATH=$DISLIN:$LD_LIBRARY_PATH
                    export LD_LIBRARY_PATH

I think the "LD_LIBRARY_PATH" thing should fix the problem of not finding the DISLIN dynamic library libdislin.so.
On my OpenSuSE linux, the library paths which work without explicit LD_LIBRARY_PATH export are listed in /etc/ld.so.conf


Good luck !


Armin


--
Dr. Armin Rauthe-Schöch
Max Planck Institute of Chemistry
Air chemistry department
Hahn-Meitner-Weg 1
D-55128 Mainz
Germany
Tel. +49-(0)6131-305-4123
Sent: Saturday, April 23, 2016 22:14
To: dislin...@googlegroups.com

Subject: Re: DISLIN with GFortran on Raspberry Pi with Raspbian

John Wasilewski

unread,
Apr 24, 2016, 10:26:19 AM4/24/16
to dislin...@googlegroups.com
Dear Armin,

Thank you for your further thoughts on the matter.  I haven't yet had an opportunity to follow your recommendations but I will do as soon as I arrive home this evening.  

I can give a tentative answer to your question, though, about whether I have followed all installation instructions in /usr/local/dislin/README, especially to make DISLIN available for general use, by creating the variables DISLIN and LD_LIBRARY_PATH, and writing location of DISLIN/bin to the PATH, in my .profile or to /etc/profile file.  

My answer is that I thought I had read, in the README file, that this would not be necessary if I installed DISLIN in /usr/local/dislin , so I have not done so.

I have therefore just looked again at the README file and I see that it states the following at f), to which I have added line numbers for reference below.

f) To make DISLIN available for general use, write the following commands to your .profile or to /etc/profile
             1       DISLIN=directory                     
             2      export DISLIN
             3       PATH=${PATH}:${DISLIN}/bin

             4       LD_LIBRARY_PATH=$DISLIN:$LD_LIBRARY_PATH
             5       export LD_LIBRARY_PATH

   Note: The environment variable DISLIN is not necessary if DISLIN
         is installed in the default directory '/usr/local/dislin'

As you see, I took the words I've coloured in red as meaning that I don't been to do ANY of 1 to 5 above.  I now see that I have almost certainly misunderstood.  Do the instructions in fact mean that only 1 and 2 are unnecessary, but that 3, 4 and 5 are still required?  If it does mean this, and the DISLIN variable is not therefore assigned a value of the DISLIN path, then do I need to alter 3, 4 and 5 to read like this:

             3       PATH=${PATH}: /usr/local/dislin/bin

             4       LD_LIBRARY_PATH=/usr/local/dislin/:$LD_LIBRARY_PATH
             5       export LD_LIBRARY_PATH

I'll write again as soon as I've done some tests tonight at home.
Many thanks again for helping so very much as you always do.
---
John

John Wasilewski

unread,
Apr 24, 2016, 1:25:31 PM4/24/16
to dislin...@googlegroups.com
Armin you're a genius!
What you told me was exactly what I needed to do.  

Does this mean that GFortran-compiled executables on Linux, with DISLIN calls, cannot run on another Linux system unless DISLIN as also been installed?
---
John

Rauthe-Schöch, Armin

unread,
Apr 24, 2016, 1:35:11 PM4/24/16
to dislin...@googlegroups.com
Hi John,

I'm glad I could help to get your DISLIN code running on a Raspberry Pi!

And yes, any code which depends on external libraries only runs when these libraries are installed on the machine. There is so called "static linking" which ships the library inside the executable (rough explanation). But I don't know how to achieve this with Linux and whether this can be achieved at all for all kind of libraries. Maybe Helmut knows how to do this for DISLIN programs.

I'm pretty sure though that it would suffice to ship the library file itself and put it somewhere on the LD_LIBRARY_PATH on the second machine. The executable just needs the library, not the header files, DISLIN tools or DISLIN help files all included in the full DISLIN distribution.

Cheers,

Armin


--
Dr. Armin Rauthe-Schöch
Max Planck Institute of Chemistry
Air chemistry department
Hahn-Meitner-Weg 1
D-55128 Mainz
Germany
Tel. +49-(0)6131-305-4123
Sent: Sunday, April 24, 2016 19:25

Helmut Michels

unread,
Apr 26, 2016, 5:57:41 AM4/26/16
to dislin-users
Dear John,

good to hear that your problem is solved. I just want to summarize how to compile and link a Fortran code with
Dislin and GFortran on Linux systems and give some more explanations. I suppose that the environment variable
DISLIN is defined with the installation directory of Dislin. For example

                                      DISLIN=/usr/local/dislin
                                      export DISLIN

Otherwise, you have to use the installation directory directly in the commands below. The environment variable
DISLIN is only used in programs for detecting font files and map coordinates. If you don't use this Dislin features,
or Dislin is installed in the default directory /usr/local/dislin, the environment variable DISLIN is not required.

a)   Compiling

      the command is:     gfortran -c  -I$DISLIN/gf     xxx.f90

      The directory $DISLIN/gf contains the Fortran 90 module file 'dislin.mod', which is needed if you have the statement
       'use dislin' in your Fortran code. The statement is not necessary, but it allows the compiler to check the number
       and type of parameters passed to Dislin routines. Unfortunately, the format of 'dislin.mod' differs from gfortran version
       to gfortran version. So, you have to recreate it with your gfortran version:

                                    cd   $DISLIN/gf
                                    gfortran -c  dislin.f90

b) Linking

    linking can be done with the command:   gfortran  xxx.o  -L$DISLIN  -ldislin

    The option -ldisdlin tells the linker to link with the library libdislin.so, and the option -L$DISLIN where to search for
    the library. The command above will create the executable a.out. If you don't like the name a.out, you can change
    it with the -o option. The library libdislin.so is just a link to libdislin.so.10, which is again a link to $DISLIN/lib/dislin-10.6.so.

c) Runtime   

    By default, programs are linked shareable with Dislin. This means that the system must load the Dislin library libdislin.so.10
    into memory, when a Dislin program is executed. The environment variable LD_LIBRARY_PATH tells the system where
    to search for shareable libraries. You have to define it with the Dislin directory:

                                 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DISLIN
                                 export LD_LIBRARY_PATH

    There are other methods such as copying libdislin.so.10 to the directory /usr/lib, but this is not done by a tar.gz
    installation of Dislin.

d) Static Linking

    Shareable linking is nice. The created programs are small and if a bug is fixed in a shareable library, it is automatically
    fixed in your program. You don't have to re-link it.A disadvantage is that the shareable libraries must be available on the
    system, where you want to execute your program. The Dislin distributions for Linux contain shareable and static libraries,
    which you can use for linking. The command for linking with the static library of Dislin is normally:

             gfortran  xxx.o  $DISLIN/libdislin.a  -lGL  -lXm  -lXt  -lX11

    -lGL is the linker option for OpenGL, and -lXm for OpenMotif.

I hope this brings a little bit light into the darkness.

Helmut 

John Wasilewski

unread,
May 1, 2016, 3:13:10 PM5/1/16
to dislin-users
Dear Helmut,

I am extremely grateful to you for going to so much trouble to explain how to use Dislin in such detail. Your level of help and support are really fantastic.
Here's my progress report. I am posting this in case others find it interesting, and not as a further request for more help from you, Helmut.

I have now successfully compiled, linked and executed your exa_f90 example using GFortran and Dislin on the Raspberry Pi 2 with Linux Raspbian.
I have done so,
(a) from the CLI, with the executable dependent on a Dislin shared library,
(b) using an IDE, with the executable dependent on a Dislin shared library,
(c) from the CLI, with the executable as a stand-alone program, needing no library support,
but not,
(d) using an IDE, with the executable as a stand-alone program, needing no library support.

The IDE I am using is the excellent Simply Fortran, from Approximatrix.com.

A difficulty I am now having with BOTH (c) and (d) (strangely, I am having this problem AFTER having successfully completed all three of (a) to (c) above) is that the linker is throwing up an error about being unable to do '-lGL' which I know is because it can't find the OpenGL library file libGL.a.

I gave researched this and I've discovered that Raspbian does not yet fully support OpenGL. It turns out that OpenGL support IS in fact included in the latest version of Raspbian, but only experimentally. It has to be enabled using RasPi-config's 'Advanced' options. When I first successfully built (c), I had not yet either discovered about OpenGL, or enabled it. What I probably had just done is to install something connected with it, but I don't recall exactly what.

Since then, however, I've been unable to repeat (c).

I gave tried enabling OpenGL as above, but that only prevented the RPi from booting at all, so I had to edit config.txt from another laptop, to change back the two lines it altered, and I can't actually enable OpenGL at the moment. Result I can no longer do (c), even though I HAVE, somehow,
I am going to wait patiently for OpenGL to be fully implemented in Raspbian, which I hope will be soon. When that happens, I expect (c) and (d) will immediately work.

If anyone knows what I must have done to gain access to libGL.a from Raspbian just now, without enabling the experimental code, I'd love to know.
---
John

Reply all
Reply to author
Forward
0 new messages