3

古い 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

4

1 に答える 1

2

編集:問題は明らかにプログラムの不足によるものではありません(申し訳ありませんが、私は起きていませんでした:-))。

実際には、行末が問題を引き起こしています。Windows で CRLF に適切に変換すると、gcc-4.8.1 は正常にコンパイルされます (ACCEPT をコメントアウトした後)。

でも:

  • 多くの警告があります (未使用の変数またはフォーマット)
  • ACCEPT はREAD と同等である必要があり、ラベル 777 がありません (READ 形式の場合)
  • 特にほとんどすべてのコードがスペースでインデントされている場合は、実際に避ける必要がある表を含む行がいくつかあります。

Windows ボックスにアクセスできる場合は、Notepad++ を使用して行末を変換し、タブを置き換えることができます。

修復するファイルが多数ある場合は、python スクリプトを試すことができます。以下について詳しく説明します。これは、特定のルールに従ってファイルをクリーンアップするためによく使用するものです (必要に応じてcleanfile関数を変更できます。ここでは、CRLF に変換し、不要な空白を削除します)。これは Python 3 ですが、必要に応じて Python 2 に簡単に変換できます。

# encoding: ISO-8859-15

import sys, os, hashlib

def filehash(name):
   f = open(name, "rb")
   h = hashlib.sha512()
   n = 4 * 1024 * 1024
   while True:
      r = f.read(n)
      h.update(r)
      if len(r) < n:
         break
   f.close()
   return h.hexdigest()

def cleanfile(name):
   v = os.stat(name)
   a = filehash(name)
   atime = v[7]
   mtime = v[8]
   f = open(name, "rt", encoding="ISO-8859-1")
   u = f.readlines()
   f.close()

   n = len(u)
   for i in range(n):
      u[i] = u[i].rstrip()

   while n > 0 and u[n - 1] == "":
      n -= 1

   if n == 0:
      print("EMPTY FILE {}".format(name))
      os.remove(name)
      return

   #f = open(name, "wt", newline="\n")
   f = open(name, "wt", encoding="ISO-8859-1")
   for i in range(n):
      s = u[i]
      f.write("{}\n".format(s))
   f.close()

   os.utime(name, (atime, mtime))
   b = filehash(name)
   if a != b:
      print("MODIF {}".format(name))

def manfile(name):
   global exts
   n = name.rfind(".")
   if n < 0:
      print("PASS {}".format(name))
   e = name[n + 1:].lower()

   if e in ["f"]:
      cleanfile(name)
   else:
      print("SKIP {}  -  {}".format(e, name))


########### recursive directory traversal, don't whange after this line ###########

def mandir(path):
   try:
      li = os.listdir(path)
   except:
      print("ERRD {}".format(path))
      return
   li.sort()
   lilnk = [ ]
   lifil = [ ]
   lidir = [ ]
   for name in li:
      c = os.path.join(path, name)
      if os.path.islink(c):
         lilnk.append(c)
      elif os.path.isfile(c):
         lifil.append(c)
      elif os.path.isdir(c):
         lidir.append(c)
      else:
         print("UNKN {}".format(c))
   for c in lilnk:
      os.remove(c)
      pass
   for c in lifil:
      manfile(c)
   for c in lidir:
      mandir(c)
   li = os.listdir(path)
   if len(li) == 0:
      try:
         os.rmdir(path)
      except OSError:
         pass

mandir(sys.argv[1])
于 2013-08-13T07:54:49.710 に答える