c - 我应该如何用 cc 编译这个旧代码

标签 c compiler-errors compilation

我正在尝试在 Ubuntu 18.04.2 LTS 中编译 2001 年的源代码。但是,我收到以下错误,实际上不知道如何更改编译代码。你能帮我编译这段代码吗?

程序中建议的编译部分

  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

当我尝试这段代码时,出现错误;

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’?

然后,我改变了-fast , -tune , -arch , -assume带有 -Ofast 的标志, -mtune=native , -march=native , -msse然后添加错误目录部分的路径。

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

然后,我得到了这个错误;

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

您可以通过此链接访问源代码; Source Code

我的电脑信息:

操作系统:Ubuntu 18.04.2 LTS

内核版本:4.15.0-50-generic

GCC 版本:7.4.0

最佳答案

gets 在 C11 中被删除。使用gcc -o mol_volume -Wall -std=c99 -mtune=native -O3 mol_volume.c -lm进行编译。

它会起作用,但您应该修复代码以删除所有警告。

关于c - 我应该如何用 cc 编译这个旧代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56199176/

相关文章:

c - 确定一个数组是否至少有一个重复项的最快算法

可能导致精度或幅度损失的 Java 隐式转换?

java - 更改 Android Eclipse 设置以忽略错误

c++ - 空格和 makefile

java - 如何从 Grails 项目中使用或引用 Java 项目?

php - 我怎样才能有效地让我的脚本休眠准确的毫秒数?

c - 第二个输入替换 scanf 和 fgets 中第一个输入的最后一个字符

c - c中if语句中表达式的求值

c++ - 在启用自动(基于扩展)选项的情况下,IAR 无法正确编译 C++ 文件

ruby - 如何在 osx 上使用调试符号从源代码编译 ruby​​?