【问题标题】:Unknown type name uint64_t and uint16_t uint8_t in Linux [closed]Linux中的未知类型名称uint64_t和uint16_t uint8_t [关闭]
【发布时间】:2019-05-22 02:29:58
【问题描述】:

我正在尝试在 Ubuntu 环境中编译一个程序,但我有一些错误说 unknown type name 'uint64_t'unknown type name 'uint16_t',即使我已经包含了 cstdint 和我认为的任何其他要求。好像是 C++ 库支持问题。

有谁知道如何解决这个问题?

【问题讨论】:

  • 请包含您的代码,显示#include。
  • 我猜你需要使用std::uint64_t,但没有代码就不能确定。代码是using namespace std; 吗? - 实际上,只需阅读此答案:stackoverflow.com/a/13643019/1730895
  • 请添加您的代码,以及用于编译的命令以及环境详细信息。
  • edit您的问题并在那里添加您的代码。
  • 您没有发布完整的代码。您需要创建一个 minimal reproducible example 来证明您的问题

标签: c++ linux


【解决方案1】:

没有看到你的代码很难回答。我代码不包含cstdintstdint.h,和/或它没有使用std::uint64_t 语法。

所以我的答案只能是你可以运行的简单测试/示例。

编译:

g++ -Wall -g --std=c++11 int64_test.cpp -o int64_test -lstdc++

代码“int64_test.cpp”:

#include <cstdint>
#include <iostream>

int main( int argc, char **argv )
{
    std::uint64_t u64 = 3;
    std::int32_t  i32 = 141;

    std::cout << "u64 = " << u64 << std::endl;
    std::cout << "i32 = " << i32 << std::endl;

    return 0;
}

此代码和编译在 Ubuntu 18.04 上运行良好。我希望它也可以在 Ubuntu 14.x 上运行

为了完整起见,一个 C 版本(因为这也被标记到问题中)

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>  // Must have this!

int main( int argc, char **argv )
{
    uint64_t u64 = 3;
    int32_t  i32 = 141;

    printf( "u64 = %lu\n", u64 );
    printf( "i32 = %d\n", i32 );

    return 0;
}

【讨论】:

    【解决方案2】:

    如果包含&lt;stdint.h&gt;,则名称应在全局命名空间中声明。

    如果包含&lt;cstdint&gt;,则需要在std:: 命名空间中将它们声明为std::uint8_t 等。允许但不要求在不带std:: 前缀的情况下声明它们。

    我通常#include &lt;stdint.h&gt;。但是,一种更时尚的方式可能是:

    #include <cstdint>
    
    using std::uint8_t;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多