Newbe: How to link .exe using multiple objects stored in a library

15 views
Skip to first unread message

scoxbike

unread,
Dec 4, 2009, 12:58:40 PM12/4/09
to gg95
Under Windows, my environment was set using these lines in a .bat
file:
set path=g:\program files\g95\bin;%path%
set LIBRARY_PATH=g:\program files\g95\bin

I've successfully compiled a quantity of .f90 source into object code
using commands like:
"g:\program files\g95\bin\g95.exe" -c angle_deg_2d.f90
"g:\program files\g95\bin\g95.exe" -c angle_rad_2d.f90

Then, I stuck them all into a library using:
"g:\program files\g95\bin\ar.exe" -crs libdutchf90.a *.o

I've got an .f90 source that is the main routine that uses/calls all
the routines now stored in the libdutchf90.a library. I've compiled
it using:
"g:\program files\g95\bin\g95.exe" -c dutch_prb.f90

and added it to the library using:
"g:\program files\g95\bin\g95.exe" -crs -llibdutchf90.a dutch_prb.o

What do I have to type at the command line or include in my .bat file,
to link the dutch_prb main line together with all the routines it
calls into an .exe? I can't find an example of using g95.exe or one
of the tools, like ar.exe, to do this.

Any takers, please?

Doug

unread,
Dec 4, 2009, 1:13:38 PM12/4/09
to gg95
Try:

g95 -o myprog.exe dutch_prb.f90 -ldutchf90

Doug

STUART COX

unread,
Dec 4, 2009, 1:43:49 PM12/4/09
to gg...@googlegroups.com
Thanks, Doug.  It's great to be able to call for help and have somebody respond.
 
First off.  I noticed that my .bat file was setting the LIBRARY_PATH to g:\program files\g95\bin rather than g:\program files\g95\lib.  I changed it to look at the \lib directory.  :^(
 
I modified your suggestion from:
"g:\program files\g95\bin\g95.exe" -o dutch_prb.exe dutch_prb.f90 -ldutchf90
to:
"g:\program files\g95\bin\g95.exe" -o dutch_prb.exe dutch_prb.f90 -llibdutchf90
because I'd put the 'lib' in front of the library's name.
Fired it up as below:
"g:\program files\g95\bin\g95.exe" -o dutch_prb.exe dutch_prb.f90 -llibdutchf90
and was told:
ld: cannot find libdutchf90.a
So, I copied libdutchf90.a from where it had been created over to g:\program files\g95\lib\libdutchf90.a
but I continue to receive the same error message from ld:
ld: cannot find libdutchf90.a
So close but still need a wee bit of help, thanks.
> --
>
> You received this message because you are subscribed to the
> Google Groups "gg95" group.
> To post to this group, send email to gg...@googlegroups.com.
> To unsubscribe from this group, send email to
> gg95+uns...@googlegroups.com.For more options, visit this
> group at http://groups.google.com/group/gg95?hl=en.
>
>
>

Doug

unread,
Dec 4, 2009, 2:05:49 PM12/4/09
to gg95
On Dec 4, 1:43 pm, STUART COX <scoxb...@shaw.ca> wrote:
> Thanks, Doug.  It's great to be able to call for help and have somebody respond.
>
> First off.  I noticed that my .bat file was setting the LIBRARY_PATH to g:\program files\g95\bin rather than g:\program files\g95\lib.  I changed it to look at the \lib directory.  :^(
>
> I modified your suggestion from:
> "g:\program files\g95\bin\g95.exe" -o dutch_prb.exe dutch_prb.f90 -ldutchf90
> to:
> "g:\program files\g95\bin\g95.exe" -o dutch_prb.exe dutch_prb.f90 -llibdutchf90
> because I'd put the 'lib' in front of the library's name.
> Fired it up as below:
> "g:\program files\g95\bin\g95.exe" -o dutch_prb.exe dutch_prb.f90 -llibdutchf90
> and was told:
> ld: cannot find libdutchf90.a
> So, I copied libdutchf90.a from where it had been created over to g:\program files\g95\lib\libdutchf90.a
> but I continue to receive the same error message from ld:
> ld: cannot find libdutchf90.a
> So close but still need a wee bit of help, thanks.

When linking to a library called libdutchf90.a with the gcc linker,
you normally do not need to write the "lib" part of the name, or the
".a" extension. So try using the line I suggested previously. If you
have the library file in a different directory you can use -L<path> to
help the linker find it.

Doug
> > gg95+unsubscr...@googlegroups.com.For more options, visit this
> > group athttp://groups.google.com/group/gg95?hl=en.

STUART COX

unread,
Dec 4, 2009, 2:49:34 PM12/4/09
to gg...@googlegroups.com
It's surprising that the linker would know enough to look at the leading characters of the specified library's name and be smart enough to remove the 'lib' characters.  Standard with linkers?  Leaving off the .a extension seems pretty normal.  Never-the-less, I've still not gotten separate compilation and linking to work.  Once I do, I'll be kicking myself for not seeing it sooner.
 
In the mean time, I did get a functioning .exe made by combining all the (long) list of .f90 source and the main .f90 source onto one big call to the compiler.  Thus:
"g:\program files\g95\bin\g95.exe" -o dutch_prb.exe dutch_prb.f90 angle_deg_2d.f90 angle_rad_2d.f90 circle_dia2imp_2d.f90 circle_exp2imp_2d.f90 circle_imp_contains_point_2d.f90 cross0_2d.f90 enorm0_2d.f90 enormsq0_2d.f90 i_modp.f90 i_random.f90 i_swap.f90 i_wrap.f90 ij_next.f90 ij_next_gt.f90 imat_print.f90 iv........
 
I've gotten a working .exe that reproduces the .out file that came with the source.  With some success under my belt, I'm encouraged to learn the g95 tool's operation until I've got it down better.
 
Further comile, link suggestions are very welcome.
> gg95+uns...@googlegroups.com.For more options, visit this
> group at http://groups.google.com/group/gg95?hl=en.
>
>
>

Doug

unread,
Dec 4, 2009, 3:32:55 PM12/4/09
to gg95


On Dec 4, 2:49 pm, STUART COX <scoxb...@shaw.ca> wrote:
> It's surprising that the linker would know enough to look at the
> leading characters of the specified library's name and be smart
> enough to remove the 'lib' characters.  Standard with linkers?  
> Leaving off the .a extension seems pretty normal.  Never-the-less,
> I've still not gotten separate compilation and linking to work.  
> Once I do, I'll be kicking myself for not seeing it sooner.

From the information you have supplied, this is probably the line you
want.

g:\"program files"\g95\bin\g95.exe -o dutch_prb.exe dutch_prb.f90 -Lg:
\"program files"\g95\lib -ldutchf90

Doug
Reply all
Reply to author
Forward
0 new messages