【发布时间】:2019-05-18 13:00:10
【问题描述】:
我正在尝试在 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
【问题讨论】:
-
错误信息本身非常明确,不是吗?您是否在 Google 或 StackOverflow 中搜索过这些消息?你发现了什么?
-
顺便说一句,那个源代码似乎有很多错误(例如,永远不要使用
gets);有没有其他选择? -
“错误信息本身很明确,不是吗?你在 Google 或 StackOverflow 中搜索过这些信息吗?你发现了什么?” - 我搜索过,但找不到任何可以解决的问题我的问题。
-
将
%i替换为%li。即使在 2001 年,gets()也很危险。但是,添加extern char *gets(char *s);应该准确地声明它,但您应该修改代码以改用fgets()。 -
相关:stackoverflow.com/q/34031514/694576(顺便说一句,gxxgle 上的第一次命中)
标签: c compiler-errors compilation