From: Nikolaus Rath on
Hello,

I am trying to use the g2 graphics library for Fortran. From what I
understood about modules in Fortran, I have to include "use
module_name" in my program and then just link it to the correct
library.

However, this is apparently not true. There is no file in the g2
library that I could include with "use" and a provided example also
just reads

program demo
real d,color
d=g2_open_PS('demo_f.ps', 4.0, 1.0)
call g2_plot(d, 50.0, 50.0)
call g2_string(d, 25.0, 75.0, 'TEST ')
color=g2_ink(d, 1.0, 0.0, 0.0)
write (6,*) color
call g2_pen(d, color)
call g2_circle(d, 20.0, 20.0, 10.0)
call g2_flush(d)
call g2_close(d)
stop
end

But when I try to compile it, I get

$ gfortran-4.1 -lg2 -o demo demo.f
/tmp/cck9nOmb.o: In function `MAIN__':
demo.f:(.text+0x50): undefined reference to `g2_open_ps_'
demo.f:(.text+0x74): undefined reference to `g2_plot_'
demo.f:(.text+0xa2): undefined reference to `g2_string_'
demo.f:(.text+0xc8): undefined reference to `g2_ink_'
demo.f:(.text+0x14a): undefined reference to `g2_pen_'
demo.f:(.text+0x170): undefined reference to `g2_circle_'
demo.f:(.text+0x17e): undefined reference to `g2_flush_'
demo.f:(.text+0x18c): undefined reference to `g2_close_'
collect2: ld returned 1 exit status

Can anyone tell me what I am doing wrong?

Thanks!

-Nikolaus

--
Nikolaus(a)rath.org | College Ring 6, 28759 Bremen, Germany
Class of 2008 - Physics | Jacobs University Bremen

»My opinions may have changed, but not the fact that I am right.«
From: Reinhold Bader on
Nikolaus Rath schrieb:
> Hello,
>
> I am trying to use the g2 graphics library for Fortran. From what I
> understood about modules in Fortran, I have to include "use
> module_name" in my program and then just link it to the correct
> library.
>

From the example one deduces that the implementation does not provide
a module at all, but only implicitly interfaced calls.
As far as the linkage problem is concerned, using a line of the form
gfortran-4.1 -o demo demo.f -L<path-to-lg2-libraries> -lg2
might be more promising, IF
* the library interface also has been built with gfortran
* the library name in the <path-to-lg2-libraries> is libg2.a or libg2.so[.*]


Regards

> However, this is apparently not true. There is no file in the g2
> library that I could include with "use" and a provided example also
> just reads
>
> program demo
> real d,color
> d=g2_open_PS('demo_f.ps', 4.0, 1.0)
> call g2_plot(d, 50.0, 50.0)
> call g2_string(d, 25.0, 75.0, 'TEST ')
> color=g2_ink(d, 1.0, 0.0, 0.0)
> write (6,*) color
> call g2_pen(d, color)
> call g2_circle(d, 20.0, 20.0, 10.0)
> call g2_flush(d)
> call g2_close(d)
> stop
> end
>
> But when I try to compile it, I get
>
> $ gfortran-4.1 -lg2 -o demo demo.f
> /tmp/cck9nOmb.o: In function `MAIN__':
> demo.f:(.text+0x50): undefined reference to `g2_open_ps_'
> demo.f:(.text+0x74): undefined reference to `g2_plot_'
> demo.f:(.text+0xa2): undefined reference to `g2_string_'
> demo.f:(.text+0xc8): undefined reference to `g2_ink_'
> demo.f:(.text+0x14a): undefined reference to `g2_pen_'
> demo.f:(.text+0x170): undefined reference to `g2_circle_'
> demo.f:(.text+0x17e): undefined reference to `g2_flush_'
> demo.f:(.text+0x18c): undefined reference to `g2_close_'
> collect2: ld returned 1 exit status
>
> Can anyone tell me what I am doing wrong?
>
> Thanks!
>
> -Nikolaus
>
From: Dr Ivan D. Reid on
On Sat, 05 Apr 2008 12:18:05 +0200, Nikolaus Rath <Nikolaus(a)rath.org>
wrote in <87myo8k3ky.fsf(a)nokile.rath.org>:

> I am trying to use the g2 graphics library for Fortran. From what I
> understood about modules in Fortran, I have to include "use
> module_name" in my program and then just link it to the correct
> library.

There are no modules. It appears that you just need to link to
the library.

> However, this is apparently not true. There is no file in the g2
> library that I could include with "use" and a provided example also
> just reads

> program demo
> real d,color
> d=g2_open_PS('demo_f.ps', 4.0, 1.0)
> call g2_plot(d, 50.0, 50.0)
> call g2_string(d, 25.0, 75.0, 'TEST ')
> color=g2_ink(d, 1.0, 0.0, 0.0)
> write (6,*) color
> call g2_pen(d, color)
> call g2_circle(d, 20.0, 20.0, 10.0)
> call g2_flush(d)
> call g2_close(d)
> stop
> end

> But when I try to compile it, I get

> $ gfortran-4.1 -lg2 -o demo demo.f
> /tmp/cck9nOmb.o: In function `MAIN__':
> demo.f:(.text+0x50): undefined reference to `g2_open_ps_'
....
> collect2: ld returned 1 exit status

> Can anyone tell me what I am doing wrong?

I think the compiler isn't passing the lib to the linker. Did you
try 'gfortran-4.1 -Xlinker -lg2 -o demo demo.f'? That's what I'd do,
having just typed 'gfortran --help'...

I'd also check the sources to see what decorated names the Fortran
interface wrappers expect; they might be using a different convention to
the one gfortran uses.

--
Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration,
Brunel University. Ivan.Reid@[brunel.ac.uk|cern.ch] Room 40-1-B12, CERN
KotPT -- "for stupidity above and beyond the call of duty".
From: FX on
> I think the compiler isn't passing the lib to the linker.

It does.

> Did you try 'gfortran-4.1 -Xlinker -lg2 -o demo demo.f'?

This is really equivalent to 'gfortran-4.1 -lg2 -o demo demo.f'.

> I'd also check the sources to see what decorated names the Fortran
> interface wrappers expect; they might be using a different convention
> to the one gfortran uses.

I think that's more probable.

--
FX
From: Dr Ivan D. Reid on
On Sat, 5 Apr 2008 12:20:23 +0000 (UTC), FX <coudert(a)alussinan.org>
wrote in <ft7qq7$s59$1(a)nef.ens.fr>:
>> I think the compiler isn't passing the lib to the linker.

> It does.

>> Did you try 'gfortran-4.1 -Xlinker -lg2 -o demo demo.f'?

> This is really equivalent to 'gfortran-4.1 -lg2 -o demo demo.f'.

OK; I still have trouble with Unix and its position-dependent
switches so I tend to try all possibilities.

>> I'd also check the sources to see what decorated names the Fortran
>> interface wrappers expect; they might be using a different convention
>> to the one gfortran uses.

> I think that's more probable.

--
Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration,
Brunel University. Ivan.Reid@[brunel.ac.uk|cern.ch] Room 40-1-B12, CERN
KotPT -- "for stupidity above and beyond the call of duty".