我有一个旧的 FORTRAN 77 程序,我无法正常编译/构建:
gfortran -Wall -o "filename" filename.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 "filename" filename.f
这给了我编译的二进制文件。好的,但 gfortran 的手册页正在勾勒我。这是 -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