home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!cs.utexas.edu!asuvax!ennews!envmsa.eas.asu.edu!ptran
- From: ptran@envmsa.eas.asu.edu (Phi-Long Tran)
- Newsgroups: comp.lang.c
- Subject: Re: HELP
- Message-ID: <30JUL199221370673@envmsa.eas.asu.edu>
- Date: 31 Jul 92 04:37:00 GMT
- References: <1992Jul30.154323.12491@cc.umontreal.ca> <rfries.82@fries_Robert@ub.ub.com>
- Sender: news@ennews.eas.asu.edu (USENET News System)
- Organization: Arizona State University, Tempe, AZ
- Lines: 92
- News-Software: VAX/VMS VNEWS 1.4-b1
-
- In article <rfries.82@fries_Robert@ub.ub.com>,
- rfries@fries_Robert@ub.ub.com (Robert Fries) writes...
- >In article <1992Jul30.154323.12491@cc.umontreal.ca>
- mikhail@ERE.UMontreal.CA (Mikhail Ossama) writes:
-
- >>#include <stdio.h>
- >>#include <stdlib.h>
- >
- >>main(int argc, char *argv[])
- >>{
- >>if (argc!=4)
- >> {
- >> printf( " Usage : ./link prog.f -o prog.exe \n ");
- >> exit(0);
- >> }
- >>system(f77 argv[1] -o argv[3] -L/usagers/garcia/gqopt/lib -lgq5 -lthomas -p);
- >>}
- >
- >Bonjour !
- >
- >Try
- >system
- >("f77 argv[1] -o argv[3] -L/usagers/garcia/ggopt/lib -lgq5 -lthomas - p");
- > ^ ^
-
- Sorry, no French. The closest I would try is German ... but that's
- not EVEN close. There are two errors:
-
- 1) The function "system" requires a string (solved in the reply by Mr.
- Ossama.
-
- 2) You need to format the string to contain the two arguments passed to the
- program in argv[1] and argv[3].
-
- Try the following:
-
- #define MAX_CMDLEN 255 /* Maximum length of command to pass to system. */
-
- main(int argc, char *argv[])
- {
- char command_string[MAX_CMDLEN];
-
- if (argc != 4)
- {
- /* Same as in original code. */
- }
-
- sprintf( command_string,
- "f77 %s -o %s -L/usagers/garcia/ggopt/lib -lgq5 -lthomas - p",
- argv[1], argv[3]);
-
- if (system( command_string ) != 0) /* Check to see if command failed. */
- {
- /* Report the error. */
- exit( EXIT_FAILURE );
- }
- else
- exit( EXIT_SUCCESS );
- }
-
- You can check your local reference manuals about the exit() call and
- the defines EXIT_FAILURE and EXIT_SUCCESS.
-
- If all you want is to spare yourself the trouble of specifying default
- arguments to f77, there are several ways. You may want to look into using
- a makefile to automate compiling and linking. If you still want to retain
- the flexibility of the above program, you can use the following UNIX shell
- script (I assume you're using UNIX from your original call to system):
-
- --- Beginning of Script ---
- #!/bin/sh
- #
- # Execute f77 with usual librariess and options. User only specifies
- # source file and name of resulting executable. No need for "-o", although
- # we can add statements to handle that.
- #
-
- if [ $# -lt 2 ]
- then
- echo "Usage: $0 source_file executable_file"
- exit 1
- fi
-
- libs="-L/usagers/garcia/ggopt/lib -lgq5 -lthomas"
-
- f77 $1 -o $2 ${libs} - p
- --- End of Script ---
-
- ---
- Phi-Long Tran
- ptran@asuvax.eas.asu.edu
- Arizona State University
-