我正在尝试在 Ubuntu 环境中编译一个程序,但我有一些错误提示unknown type name 'uint64_t',unknown type name 'uint16_t'即使我已经包含了cstdint我相信的任何其他要求。似乎是 C++ 库支持问题。
有谁知道如何解决这一问题?
如果没有看到您的代码,很难回答。我猜代码不包含cstdintor stdint.h,和/或它没有使用std::uint64_t语法。
所以我的答案只能是一个可以运行的简单测试/示例。
编译它:
g++ -Wall -g --std=c++11 int64_test.cpp -o int64_test -lstdc++
Run Code Online (Sandbox Code Playgroud)
代码“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;
}
Run Code Online (Sandbox Code Playgroud)
此代码和编译在 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;
}
Run Code Online (Sandbox Code Playgroud)