[comp.sys.hp] Unix

valdi@rhi.hi.is (Thorvaldur Sigurdsson) (03/20/90)

Subject: Unix (HP-UX) system call from ADA
Newsgroups: comp.sys.hp,comp.lang.ada
Keywords: ADA


Problem       : Making unix system calls within Ada code
Background    : HP-UX 6.5, HP 9000/300 series, Alsys 4.35 Ada compiler
Error message : 
		ld: Undefined external -
		      _ll
		      _clear
		ld: output file still contains undefined symbols
		ld: (Warning) did not generate an output file
		ada: Errors detected

Manual 	      : Reference Manual for the Ada Programming Language,
		Appendix F, page F-5, chapter F 1.1.4 Additional
		Information on INTERFACE and INTERFACE_NAME :

	       "When you want to call an HP-UX system call from Ada
		code, you should use a pragma INTERFACE with C as the
		language name.  It is not necassary to provide the C
		object file to the binder, because it will be found 
		automatically when the linker searches the system
		library".

Question      : Is the manual wrong concerning automatic linking or
		am I doing something wrong in the code ?

Source code   : main.ada, system.ads

main.ada      : The following source is the main procedure

		-- ************************************************
		-- *   ABSTRACT: Main program                     *
		-- ************************************************

		procedure MAIN is

		begin 

  	  	  UNIX_SYSTEM_CALL.clear;
  	  	  UNIX_SYSTEM_CALL.ll;

		end MAIN;


system.ads    : The following source is the unix_system_call package

		-- ************************************************
		-- *   ABSTRACT: Package specification  	  *
		-- ************************************************

		package UNIX_SYSTEM_CALL is
 	 
	  	  procedure clear;
	  	  procedure ll;

		private

  	  	  pragma INTERFACE (C, clear);  -- clear display
  	  	  pragma INTERFACE (C, ll);	-- long list

		end UNIX_SYSTEM_CALL;  -- package specification


P.S.	      : I tried also implementing the usage of INTERFACE_NAME 
		without results.
------------------------------------------------------------------------
Thorvaldur Egill Sigurdsson    | 
Engineering Research Institute | Internet: valdi@kerfi.hi.is  
University of ICELAND	       | 
Hjardarhagi 2-6	               | Phone: 354-1-694699
107 Reykjavik, ICELAND         |
------------------------------------------------------------------------

karl@grebyn.com (Karl A. Nyberg) (03/21/90)

In article <1587@krafla.rhi.hi.is> valdi@rhi.hi.is (Thorvaldur Sigurdsson) writes:

%Problem       : Making unix system calls within Ada code
%Background    : HP-UX 6.5, HP 9000/300 series, Alsys 4.35 Ada compiler
%Error message : 
%		ld: Undefined external -
%		      _ll
%		      _clear
%		ld: output file still contains undefined symbols
%		ld: (Warning) did not generate an output file
%		ada: Errors detected
%
%	       "When you want to call an HP-UX system call from Ada
%		code, you should use a pragma INTERFACE with C as the
%		language name.  It is not necassary to provide the C
%		object file to the binder, because it will be found 
%		automatically when the linker searches the system
%		library".
%
%Question      : Is the manual wrong concerning automatic linking or
%		am I doing something wrong in the code ?
%

My guess is you are trying to use not SYSTEM calls, but calls to units in
some particular libraries (e.g. curses?).  In those cases, you will need to
include the C object file to the binder (possibly the archive file?) to
resolve those names.

Or, are you trying to use the shell commands "clear" and "ls -l"?  In which
case you're asking an entirely different set of questions, for which the
answer is a convoluted use of either the "system" call (if it exists on your
machine) or getting an interface to fork and/or exec.

-- Karl --

gallag@hp-and.HP.COM (Mike Gallagher) (03/21/90)

> Problem       : Making unix system calls within Ada code
> Background    : HP-UX 6.5, HP 9000/300 series, Alsys 4.35 Ada compiler
> Error message : 
> 		ld: Undefined external -
> 		      _ll
> 		      _clear
> 		ld: output file still contains undefined symbols
> 		ld: (Warning) did not generate an output file
> 		ada: Errors detected
> 
> 
> 		procedure MAIN is
> 
> 		begin 
> 
>   	  	  UNIX_SYSTEM_CALL.clear;
>   	  	  UNIX_SYSTEM_CALL.ll;
> 
> 		end MAIN;
> 
> 
> system.ads    : The following source is the unix_system_call package
> 
> 		-- ************************************************
> 		-- *   ABSTRACT: Package specification  	  *
> 		-- ************************************************
> 
> 		package UNIX_SYSTEM_CALL is
>  	 
> 	  	  procedure clear;
> 	  	  procedure ll;
> 
> 		private
> 
>   	  	  pragma INTERFACE (C, clear);  -- clear display
>   	  	  pragma INTERFACE (C, ll);	-- long list
> 
> 		end UNIX_SYSTEM_CALL;  -- package specification
> 

Using the HP Ada compiler on a HP-UX A.B3.10 U 9000/855 machine, I use the
following:


with SYSTEM_ENVIRONMENT;

procedure MAIN is

LOCAL_STATUS : SYSTEM_ENVIRONMENT.EXIT_STATUS;

begin

  LOCAL_STATUS := SYSTEM_ENVIRONMENT.EXEC_SHELL_COMMAND("clear");
  LOCAL_STATUS := SYSTEM_ENVIRONMENT.EXEC_SHELL_COMMAND("ll");

end MAIN;


Perhaps your compiler has a similar SYSTEM_ENVIRONMENT package.

Mike Gallagher
gallag@hp-and

defaria@hpclapd.HP.COM (Andy DeFaria) (03/22/90)

This repsonse   is a pointer  to  the  notes   group comp.lang.ada  where a
solution to this problem is proposed.