Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LD.EXE (GNU Linker) Syntax Problem

Status
Not open for further replies.

NWR

Programmer
Jun 7, 2018
1
0
0
CA
Hello:

Listed below is the output from a very simple BATCH file to compile, library
and link 2 Fortran files (these files do nothing but exist). I have never used
GNU "programs" before (just IBM, DEC and Microsoft). I now have the
"opportunity" to use these programs (yes I need to use G77). Is it possible for
someone to explain why LD.EXE can not link. Thanks.

ie: I have tried multiple file extensions (.f, .for, .obj, .o, .a, .out, .exe) and
nothing seems to matter.

Screen Output:

TEST.BAT INFO: (Windows 7 Pro SP1)

Microsoft Windows [Version 6.1.7601]
CD...............:C:\ABC
PROGRAM_NAME.....:ABC
SUBROUTINE.......:DEF
COMP_IMAGE.......:C:\ABC\BIN\G77.EXE
LIB_IMAGE........:C:\ABC\BIN\AR.EXE
LINK_IMAGE.......:C:\ABC\BIN\LD.EXE
FORTRAN_EXT......:FOR
OBJECT_EXT.......:OBJ
LIBRARY_EXT......:LIB
LIBRARY_PATH.....:C:\ABC
LINK_EXT.........:EXE
*** GNU VERSION INFO ***
g77 version 2.95 19990728 (release) (from FSF-g77 version 0.5.25 19990728
(release))
Driving: C:\ABC\BIN\G77.EXE -v -c -xf77-version /dev/null -xnone
G77.EXE: /dev/null: No such file or directory
Using builtin specs.
gcc version 2.95 19990728 (release)
GNU ar 2.9.4
Copyright 1997, 1998 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License. This program has absolutely no warranty.
GNU ld version 2.9.4 (with BFD 2.9.4)
Supported emulations:
i386pe
. Press ENTER to Continue:
*** DIR OF FORTRAN FILES ***
ABC.FOR
DEF.FOR
. Press ENTER to COMPILE:
*** COMPILE ***

C:\ABC>C:\ABC\BIN\G77.EXE -c -o ABC.OBJ ABC.FOR

C:\ABC>C:\ABC\BIN\G77.EXE -c -o DEF.OBJ DEF.FOR
DIR OF OBJECT FILES
ABC.OBJ
DEF.OBJ
. Press ENTER to LIBRARY:
*** LIBRARY ***

C:\ABC>C:\ABC\BIN\AR.EXE r ABC.LIB DEF.OBJ
DIR OF LIBRARY FILES
ABC.LIB
LIBRARY LISTING

C:\ABC>C:\ABC\BIN\AR.EXE t ABC.LIB
DEF.OBJ
. Press ENTER to LINK:
*** LINK ***

C:\ABC>C:\ABC\BIN\LD.EXE -o ABC.EXE -l ABC.LIB ABC.OBJ
C:\ABC\BIN\LD.EXE: cannot open -lABC.LIB: No such file or directory

C:\ABC>C:\ABC\BIN\LD.EXE -o ABC.EXE -L C:\ABC -l ABC.LIB ABC.OBJ
C:\ABC\BIN\LD.EXE: cannot open -lABC.LIB: No such file or directory
. Press ENTER to EXIT:

C:\ABC>
 
This is just a guess - I'm not sure of the behaviour of linux tools on windows. When a -l parameter is given to ld, it expects the item named to have a lib prefix and a .a or .so suffix, so

Code:
ld -o abc.exe -labc.lib

will expect a libabc.lib.a to exist. ar, however does not add a lib prefix or the .a suffix so you need to do that.

Code:
ar r libabc.a def.obj
ld -o abc.exe -labc
 
I've just installed mingw gfortran. It looks like ld needs the fortran libraries so it might be better if you use g77 to do the linking. Also, ld, needs -L for the path of the library

Code:
g77.exe -c -g def.for -o def.obj
ar r libabc.a def.obj
g77.exe abc.for -L. -labc -o abc.exe
 
Personally I would have installed the development packages for cygwin from It is all the unix commands ported over to windows and for the FORTRAN I would use gfortran which works great. When you install the development packages it installs all the dependencies so it just works.

Bill
Lead Application Developer
New York State, USA
 
You can compile fortran 77 using gfortran - you don't have to use g77. Just give the files either a .f or .for extension.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top