home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11796 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.9 KB  |  105 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!cs.utexas.edu!asuvax!ennews!envmsa.eas.asu.edu!ptran
  2. From: ptran@envmsa.eas.asu.edu (Phi-Long Tran)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP
  5. Message-ID: <30JUL199221370673@envmsa.eas.asu.edu>
  6. Date: 31 Jul 92 04:37:00 GMT
  7. References: <1992Jul30.154323.12491@cc.umontreal.ca> <rfries.82@fries_Robert@ub.ub.com>
  8. Sender: news@ennews.eas.asu.edu (USENET News System)
  9. Organization: Arizona State University, Tempe, AZ
  10. Lines: 92
  11. News-Software: VAX/VMS VNEWS 1.4-b1
  12.  
  13. In article <rfries.82@fries_Robert@ub.ub.com>, 
  14. rfries@fries_Robert@ub.ub.com (Robert Fries) writes...
  15. >In article <1992Jul30.154323.12491@cc.umontreal.ca> 
  16. mikhail@ERE.UMontreal.CA (Mikhail Ossama) writes:
  17.  
  18. >>#include <stdio.h>
  19. >>#include <stdlib.h>
  20. >>main(int argc, char *argv[])
  21. >>{
  22. >>if (argc!=4)
  23. >> { 
  24. >>  printf( " Usage : ./link prog.f -o prog.exe \n ");
  25. >>  exit(0); 
  26. >> }
  27. >>system(f77 argv[1] -o argv[3] -L/usagers/garcia/gqopt/lib -lgq5 -lthomas -p);
  28. >>}
  29. >Bonjour !
  30. >Try
  31. >system
  32. >("f77 argv[1] -o argv[3] -L/usagers/garcia/ggopt/lib -lgq5 -lthomas - p");
  33. > ^                                                                     ^
  34.  
  35.      Sorry, no French.  The closest I would try is German ... but that's
  36. not EVEN close.  There are two errors:
  37.  
  38. 1) The function "system" requires a string (solved in the reply by Mr.
  39. Ossama.
  40.  
  41. 2) You need to format the string to contain the two arguments passed to the
  42. program in argv[1] and argv[3].
  43.  
  44.      Try the following:
  45.  
  46. #define MAX_CMDLEN 255 /* Maximum length of command to pass to system. */
  47.  
  48. main(int argc, char *argv[])
  49. {
  50.    char command_string[MAX_CMDLEN];
  51.  
  52.    if (argc != 4)
  53.    {
  54.       /* Same as in original code. */
  55.    }
  56.  
  57.    sprintf( command_string, 
  58.       "f77 %s -o %s -L/usagers/garcia/ggopt/lib -lgq5 -lthomas - p", 
  59.       argv[1], argv[3]);
  60.  
  61.    if (system( command_string ) != 0) /* Check to see if command failed. */
  62.    {
  63.       /* Report the error. */
  64.       exit( EXIT_FAILURE );
  65.    }
  66.    else
  67.       exit( EXIT_SUCCESS );
  68. }
  69.  
  70.      You can check your local reference manuals about the exit() call and
  71. the defines EXIT_FAILURE and EXIT_SUCCESS.
  72.  
  73.      If all you want is to spare yourself the trouble of specifying default
  74. arguments to f77, there are several ways.  You may want to look into using
  75. a makefile to automate compiling and linking.  If you still want to retain
  76. the flexibility of the above program, you can use the following UNIX shell
  77. script (I assume you're using UNIX from your original call to system):
  78.  
  79. --- Beginning of Script ---
  80. #!/bin/sh
  81. #
  82. # Execute f77 with usual librariess and options.  User only specifies
  83. # source file and name of resulting executable.  No need for "-o", although
  84. # we can add statements to handle that.
  85. #
  86.  
  87. if [ $# -lt 2 ]
  88.    then
  89.    echo "Usage: $0 source_file executable_file"
  90.    exit 1
  91. fi
  92.  
  93. libs="-L/usagers/garcia/ggopt/lib -lgq5 -lthomas"
  94.  
  95. f77 $1 -o $2 ${libs} - p
  96. --- End of Script ---
  97.  
  98. ---
  99. Phi-Long Tran
  100. ptran@asuvax.eas.asu.edu
  101. Arizona State University
  102.