3

パッケージの可視性に問題があります。私は本当にシンプルなパッケージを持っており、コードは以下のとおりです。エラーメッセージは次のとおりです。

viterbi.adb:12:14: "Integer_Text_IO" is not visible (more references follow)
viterbi.adb:12:14: non-visible declaration at a-inteio.ads:18
gnatmake: "viterbi.adb" compilation error

パッケージの仕様は次のとおりです。

package Viterbi is

  procedure Load_N_File(
    Filename : in String;
    N : in out Integer;
    M : in out Integer);

end Viterbi;

パッケージ本体は次のとおりです。

with Ada.Integer_Text_IO; use with Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;

package body Viterbi is

  procedure Load_N_File(
    Filename : in String;
    N : in out Integer;
    M : in out Integer
  ) is
    N_File : File_Type;
  begin
    Open( N_File, Mode=>In_File, Name=>Filename );
    Get( N_File, N ); 
    Get( N_File, M );
    Close( N_File ); 
  end Load_N_File;

end Viterbi;

パッケージ本体の何がパッケージを隠したままにしているのですか?use句はInteger_Text_IOを表示するべきではありませんか?

4

2 に答える 2

5

提供されているパッケージ本体のコードに構文エラーがあります。「usewithAda.Integer_Text_IO;」の偽の「with」です。句。

これを修正すると、 File_TypeOpen、およびCloseを解決できないことを中心にコンパイルエラーが発生します。Ada.Text_IOの「with」と「use」を追加すると、クリーンなコンパイルが得られます。

したがって、パッケージ本体の開始は次のようになります。

with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Text_IO; use Ada.Text_IO;

package body Viterbi is
   ...

これらのエラーを修正した後も「Integer_Text_IOが見つかりません」というエラーが引き続き発生する場合は、開発環境について疑わしいと思います。つまり、すべてが正しくインストールされていますか?

于 2011-02-05T01:16:49.340 に答える
2

すでに指摘したように、カンマ区切りのスタイルを使用することで、「usewith」スタイルのエラーを回避できます。With--Testing、Ada.Integer_Text_IO、Ada.Strings;

Use
-- Testing,
Ada.Strings,
Ada.Integer_Text_IO;

これにより、示されているように、特定のパッケージ「withs」または「usues」をコメントアウトすることもできます。

于 2011-02-08T23:41:15.063 に答える