我有一个老的FORTRAN 77程序,我在使用以下命令进行编译/构建时遇到了问题:
最终,我尝试了:
链接到源代码: http://nanocluster.umeche.maine.edu/ljewald.f
gfortran -Wall -o "文件名" 文件名.f
它一直给我链接器错误提示:$ gfortran -Wall ljewald.f
/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
最终,我尝试了:
gfortran -Wall -c -o "文件名" 文件名.f
这个命令生成了可执行二进制文件。很好,但是 gfortran 的 man 手册让我感到有些困惑。下面是 -c 选项的相关内容,这个选项使得编译工作变得更加顺利: -C Do not discard comments. All comments are passed through to the output file, except for comments in processed directives, which are deleted
along with the directive.
You should be prepared for side effects when using -C; it causes the preprocessor to treat comments as tokens in their own right. For example,
comments appearing at the start of what would be a directive line have the effect of turning that line into an ordinary source line, since the
first token on the line is no longer a '#'.
Warning: this currently handles C-Style comments only. The preprocessor does not yet recognize Fortran-style comments.
因此,在构建完成后,使用以下命令:
gfortran -Wall -c -o "ljewald" ljewald.f
我得到了一个输出文件,但它不是可执行文件...?
$ls -l
...
-rw-rw-r-- 1 j0h j0h 647 Aug 9 16:36 ljewald
...
即使我使用chmod +x ljewald更改模式,也无法执行此文件。
我应该怎么做才能避免-c选项,因为使用它有一些怪异之处?如何构建此程序的可执行文件?有人可以解释并告诉我如何解决吗?
/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
链接到源代码: http://nanocluster.umeche.maine.edu/ljewald.f
-c
还是-C
?它们都出现在你的问题中... - Floris