Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,
I've been working on adding functionality to a program I'm working on and would like to use std::Threads to add multi-threading. What I've noticed is that when adding #include<thread> a compilation error occurs with the error-error C2371: 'int8_t' : redefinition; different basic types"

What can be done to correct this?
Posted
Comments
Richard MacCutchan 6-Jun-14 12:34pm    
We cannot answer that without the information about what includes you have in your source code and where the error occurs.

KarnstenK sort of gives you the correct answer but it needs expanding

There are two units both trying to define "int8_t" and one of those is part of the standard C library it will be in "StdInt.H" in the system include directory of any C99 compliant compiler.

Fixed width integer types (since C99)
http://en.cppreference.com/w/c/types/integer[^]

As you are using the standard libraries that you can not get around that unit.

You need to find the none system unit that is also trying to define int8_t and see if you can fix it. There are a number of ways to do that from using #ifndef thru to renaming the non standard unit using of int8_t to a new name.

However to start you need to find what the second unit is that contains the name int8_t because it really shouldn't be defining that particular name and personally I would fix that unit.
 
Share this answer
 
Comments
[no name] 6-Jun-14 23:26pm    
5ed.
Stefan_Lang 13-Aug-15 2:41am    
totally agree, specifically with that last statement ;-)
+5
int8_t should be defined in cstdint header. Possibly a non-standard header redefines it. I am pretty sure the compiler is reporting what are the conflicting headers.
 
Share this answer
 
you got to change the included headers. Exclude the header which you REALLY NEED ("primary"), to find the part where else it is defined and try to exlude it, or include the "secondary" header AFTER the "primary".

It is in most cases somehow an configuration problem of your project.
 
Share this answer
 
just put the word "signed" so that the compiler knows it for sure

C#
typedef signed __int8            int8_t;
typedef signed __int16           int16_t;
typedef signed __int32           int32_t;
typedef signed __int64           int64_t;
typedef unsigned __int8   uint8_t;
typedef unsigned __int16  uint16_t;
typedef unsigned __int32  uint32_t;
typedef unsigned __int64  uint64_t;
 
Share this answer
 
Comments
Stefan_Lang 13-Aug-15 2:54am    
No! These are standard types and should never be overridden! So if there is a second definition beyond the definition in stdint.h (or cstdint), then it should be eliminated or replaced by the appropriate #include!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900