Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fortran library system calls for UNIX

11 views
Skip to first unread message

Aladdin Nassar

unread,
Dec 16, 1990, 3:54:27 PM12/16/90
to

I am trying to use the fortran library function 'system' to execute a UNIX
command from within a fortan program on the SUN SPARC workstations. (check
man 3f system). The test program is as follows :

c--------------test.f----------------------------
program test
integer system
i=system('/bin/ls')
stop
end
c------------------------------------------------


I compile and link as follows :

f77 -o test test.f -lU77

and I get the error message :

ld: Undefined symbol
_units


I tried the same code and procedure on a DEC 5400 and it worked fine with
no error message.

What could be the problem ? Could _units be defined in other archives
libraries ? Would using the 'nm' command help solve this problem ?

Please respond by e-mail to al...@portia.stanford.edu (I don't follow USENET
constantly) and I will summarize if there are any responses.

Thanks,

Aladdin Nassar
Gradute Student
Civil Engineering,
Stanford Univeristy

Aladdin Nassar

unread,
Dec 19, 1990, 6:09:52 PM12/19/90
to

WIth reference to the question I posted to this newsgroup concerning fortran
library system calls to UNIX on SPARC SunOS 4.0.3c :


c--------------------------------------------


program test
integer system
i=system('/bin/ls')
stop
end
c--------------------------------------------

f77 -o test test.f -lU77

ld: Undefined symbol
_units


Here is a summary of the responses I got:
(Thank you very much all of you out there who responded. I could not reach
everybody as some mail bounced back. So thanks again)

1- Several people tried the same code on their machines (3/260,4/370 running
fortran f77 1.2 and 1.3.1 and the code worked fine. Referrals were made to
check for incomplete or misplaced libraries and setting the LD_LIBRARY_PATH.

2- The most important messages I got from Keith Bierman at Sun as follows :
#----------------------------------------------------------------------
From k...@Eng.Sun.COM Mon Dec 17 15:43:57 1990

Old bug. Get a copy of the current compiler; or at least get the patch
from the USAC.
#----------------------------------------------------------------------
From k...@Eng.Sun.COM Mon Dec 17 15:43:57 1990

[...in response to the question about how to get the version number of
the compiler and what is USAC...]


f77 -v

minimally shows where the compiler executes stuff from. In the "modern
era" you can use -V which is more specific (but from your question, it
appears that you have f77v1.1 or perhaps v1.2; rather than v1.3.1 or
later).

Also, in the old days, there was a file lang_info lurking about which
kept track of which version is installed on the system (clearly a
problem for those of us with a desire for 2 or more co-loaded ;>).

USAC is the US answer center. Presumably your instition has maintance
agreements, which include the info they will require ("authorization
numbers" or some such). The phone number is, if memory serves, 1 800
USA 4 SUN.

Depending on release, the fix may vary. If memory serves, you just
create a dummy module which defines _units and the problem goes away
... but check with the AC.
#----------------------------------------------------------------------


It seems I have the old fortran compiler v1.1. After making sure that it
is a compiler bug (not a shortcoming on my part), I dug out my old C & UNIX
notes and wrote this C code emulating the 'system' call and it works fine.


#-------------------mysystem.c file------------------------------------
#include <sys/wait.h>

mysystem_(command,arg)
char *command,*arg;
{
union wait status;
if (fork()==0)
{ /* child process */
execlp(command,"program",arg,(char *)0);
perror("error executing mysystem");
exit();
}
else
/* parent process */
wait(&status);
return;
}
#----------------------------------------------------------------------

c-------------------test.f file----------------------------------------
program test
call mysystem('/bin/ls','-l')
stop
end
c----------------------------------------------------------------------

compiled and linked as follows :

cc -c mysystem.c
f77 -o test test.f mysystem.o


#----------------------------------------------------------------------

Thank you very much again,


Aladdin Nassar
Civil Engineering
Stanford University

0 new messages