12

I'm trying to compile a program in Ubuntu environment but I'm having some error saying unknown type name 'uint64_t', unknown type name 'uint16_t' even though I have included cstdint and any other requirements I believe. It seems like the C++ library support issue.

Does anyone know how to fix this?

klin
  • 131
  • 1
  • 1
  • 5

2 Answers2

7

Without seeing your code it's very hard to answer. I guess the code does not include cstdint or stdint.h, and/or it is not using the std::uint64_t syntax.

So my answer can only be a simple test/example you can run.

Compile it with:

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

The Code "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;
}

This code & compilation works fine on Ubuntu 18.04. I expect it will also work on Ubuntu 14.x

For the sake of completeness, a C version (since this is(was) tagged into the question too)

#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;
}
Kingsley
  • 14,398
  • 5
  • 31
  • 53
3

If you include <stdint.h>, the names should be declared in the global namespace.

If you include <cstdint>, an implementation will declare them in the std:: namespace, as std::uint8_t, etc. It is allowed, but not required, to also declare them without the std:: prefix. (Pedantically, an implementation for some architecture with a weird word size would be allowed to have no int64_t, and only declare int_least54_t and int_fast64_t, but none that I know of actually do.)

I usually #include <stdint.h>. However, a more fashionable way to do it might be:

#include <cstdint>

using std::uint8_t, std::uint16_t, std::uint64_t;
Davislor
  • 14,674
  • 2
  • 34
  • 49