Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown type name uint64_t and uint16_t uint8_t in Linux [closed]

Tags:

c++

linux

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?

like image 921
klin Avatar asked May 22 '19 02:05

klin


People also ask

What include for uint8_t in C?

To use the uint8_t type alias, you have to include the stdint. h standard header. To avoid a warning, warning: incompatible implicit declaration of built-in function 'printf' , it may be required to explicitly add #include <stdio.

What is uint16_t in C?

uint16_t is unsigned 16-bit integer. unsigned short int is unsigned short integer, but the size is implementation dependent. The standard only says it's at least 16-bit (i.e, minimum value of UINT_MAX is 65535 ).


1 Answers

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;
}
like image 92
Kingsley Avatar answered Sep 23 '22 13:09

Kingsley