-4

I'm trying to compile source code, that from 2001, in Ubuntu 18.04.2 LTS. But, I got the errors below and actually don't know how I have to change the compiling code. Can you help me for compiling this code?

Suggested compilation part from the program

  SUGGESTED COMPILATION COMMAND LINE (FOR A DEC-ALPHA CC-COMPILER):

  cc -lm -fast -tune host -arch host -assume whole_program \
     -o mol_volume mol_volume.c

When I tried this code, errors;

cc: error: host: No such file or directory
cc: error: host: No such file or directory
cc: error: whole_program: No such file or directory
cc: error: unrecognized command line option ‘-fast’; did you mean ‘-Ofast’?
cc: error: unrecognized command line option ‘-tune’; did you mean ‘-mtune=’?
cc: error: unrecognized command line option ‘-arch’; did you mean ‘-march=’?
cc: error: unrecognized command line option ‘-assume’; did you mean ‘-msse’?

Then, I changed -fast, -tune, -arch, -assume flags with -Ofast, -mtune=native, -march=native, -msse then add the path the for the directory part of the errors.

cc -lm -Ofast -mtune=native -march=native -msse /mypath/ -o mol_volume mol_volume.c

Then, I got that error;

mol_volume.c: In function ‘main’:
mol_volume.c:235:10: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
   while( gets(s) ) {
          ^~~~
          fgets
mol_volume.c:311:26: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
    printf("WARNING: the %i-th atom of the pdb file %s has an unknown chemical type %s.\n",
                         ~^
                         %li
      i+1, pdb_name, atom_type);
      ~~~                  
/usr/bin/ld: cannot find .: File format not recognized
collect2: error: ld returned 1 exit status

You can access the source code via this link; Source Code

My PC info:

Operation System: Ubuntu 18.04.2 LTS

Kernel ver.: 4.15.0-50-generic

GCC ver.: 7.4.0

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    The error messages are very explicit themselves, aren't they? Did you search for those messages in Google or StackOverflow? What did you find? – alx - recommends codidact May 18 '19 at 13:26
  • 1
    By the way, that source code seems to be very buggy (`gets` should never be used, for example); is there any alternative? – alx - recommends codidact May 18 '19 at 13:29
  • "The error messages are very explicit themselves, aren't they? Did you search for those messages in Google or StackOverflow? What did you find? " - I searched but I cannot find anything that can solve my problem. – Mert Gölcük May 18 '19 at 13:48
  • 2
    Replace the `%i` with `%li`. Even in 2001, `gets()` was dangerous. However, adding `extern char *gets(char *s);` should declare it accurately, but you should revise the code to use ``fgets()`` instead. – Jonathan Leffler May 18 '19 at 14:04
  • 1
    Related: https://stackoverflow.com/q/34031514/694576 (1st hit on gxxgle BTW) – alk May 18 '19 at 14:43

1 Answers1

2

gets was removed in C11. Compile with gcc -o mol_volume -Wall -std=c99 -mtune=native -O3 mol_volume.c -lm.

It will work but you should fix the code to remove all the warnings.