Syntax VHDL:(vcom-1136:std_逻辑_向量未定义)

Syntax VHDL:(vcom-1136:std_逻辑_向量未定义),syntax,vhdl,Syntax,Vhdl,得到一个似乎无法解释的语法错误,说std_逻辑未定义,即使它在代码的早期编译!第一个错误发生在实体的开头或第37行。我相信这与创建我自己的包有关,但这是我以前做过的事情,从来没有出现过这个错误!谢谢你的帮助 library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; package lab2 is constant SWIDTH: integer := 4; subtype

得到一个似乎无法解释的语法错误,说std_逻辑未定义,即使它在代码的早期编译!第一个错误发生在实体的开头或第37行。我相信这与创建我自己的包有关,但这是我以前做过的事情,从来没有出现过这个错误!谢谢你的帮助

  library IEEE;
  use IEEE.std_logic_1164.all;
  use IEEE.std_logic_unsigned.all;

  package lab2 is  
  constant SWIDTH: integer := 4;
  subtype state_type is 
    std_logic_vector(SWIDTH-1 downto 0); 

  constant S1: state_type  := "0000"; --these are the "reset states"
  constant S2: state_type  := "0001";
  constant S3: state_type  := "0010";
  constant S4: state_type  := "0011";
  constant S5: state_type  := "0101";
  constant S6: state_type  := "0110";
  constant S7: state_type  := "0111"; -- these are the "show letter" states
  constant S8: state_type  := "1000";
  constant S9: state_type  := "1001";
  constant S10: state_type := "1010";
  constant S11: state_type := "1011";

  constant G : std_logic_vector(7 downto 0) := x"47";
  constant a : std_logic_vector(7 downto 0) := x"61";
  constant r : std_logic_vector(7 downto 0) := x"72";
  constant e : std_logic_vector(7 downto 0) := x"65";
  constant send1 : std_logic_vector(7 downto 0) := x"38";
  constant send2 : std_logic_vector(7 downto 0) := x"0C";
  constant send3 : std_logic_vector(7 downto 0) := x"01";
  constant send4 : std_logic_vector(7 downto 0) := x"06";
  constant send5 : std_logic_vector(7 downto 0) := x"80";

end package;

------------------------------------

entity lab2 is
    port(     key : in std_logic_vector(3 downto 0);  -- pushbutton switches
            sw : in std_logic_vector(8 downto 0);  -- slide switches
            ledg : out std_logic_vector(7 downto 0);
            lcd_rw : out std_logic;
            lcd_en : out std_logic;
            lcd_rs : out std_logic;
            lcd_on : out std_logic;
            lcd_blon : out std_logic;
            lcd_data : out std_logic_vector(7 downto 0);
            hex0 : out std_logic_vector(6 downto 0));  -- one of the 7-segment diplays
end lab2 ;

该错误发生在端口中,它给出了std_逻辑和std_逻辑向量是未知的引用。

使用IEEE.std_逻辑1164。在
实体之前也需要所有的
,例如:

library IEEE;
use IEEE.std_logic_1164.all;

entity lab2 is
第一个
IEEE.std_logic_1164.all
仅适用于同一包的
包和
包体
,但不适用于任何其他设计对象,如
实体
,即使它们恰好位于同一文件中


这允许在同一文件中创建不同的设计对象,同时仍然控制库和包中的可见对象

这修复了std_逻辑错误,但不是我定义的类型state_type给了我一个未知的引用。我是否也必须以某种方式包含包lab2?我在
lab2
包之外没有看到对
state\u type
类型的引用,那么“未知引用”错误从何而来?如果您在另一个实体中使用
lab2
state\u type
类型,则添加
use work.lab2.all
,或
use work.lab2.all
,以参考
state\u type
作为
lab2.state\u type
。啊,很抱歉,我没有在帖子中包含的代码中有进一步的内容。这似乎已经纠正了我的错误,非常感谢!除了Morten的回答之外,至少还有一件事需要解决。两个主要单元(包、实体、配置)不能在同一个库(工作)中具有相同的简单名称。有两种明显的解决方案,更改包的名称(例如lab2_pkg)或将其放入单独的库中。参见IEEE Std 1076-2008 13.1设计单位第5段。@gurtn:如果这是您问题的答案,请点击复选标记接受答案,如所述。更多信息请参阅。