uint8_t and unsigned char linking error
Asked Answered
B

3

5

I'm using template function:

template<typename T> void func(const T& value)
{
    obj->func(value);
}

where obj is object of class:

void my_object::func(int64_t value) { ... }
void my_object::func(uint64_t value) { ... }
void my_object::func(uint32_t value) { ... }
void my_object::func(uint16_t value) { ... }
void my_object::func(uint8_t value) { ... }

The problem is with uint8_t overload of my_object::func() override. Linker complains about unresolved external symbols to overloads, which should have unsigned char parameter.

Should I replace uint8_t overload with unsigned char overload?

Edit: Just now noticed, that linker complains about uint64_t and int64_t too.

I compile on Windows using MSVC++ 2008 Express.

Edit: Apologies, I declared my_object::func(uint8_t value) function (and other), but I didn't defined it.

Breakthrough answered 1/1, 2011 at 15:29 Comment(4)
Incidentally, what is your compiler?Fulgurous
What is the exact error message you're getting?Stentor
You should try to reduce the problem scope and give more details on what you are actually doing. Is it really because of the template - what happens if you make a direct call of obj::func() instead? How do you define your class, and where and how you have it implemented? With only the description that you provided people would have to guess what is actually happening.Aholla
Make sure you use the same headers and thus typedefs of those integer types. MSVC has defects with how it resolves equivalent types. In certain cases two types are C++ identical but MSVC has distinct internal types for them. Those internal types make it to the linker, thus a mismatch.Antilebanon
D
8

This is the include file should #include to use the above mentioned types (C99 recommendations)

#include <stdint.h>

Drear answered 1/1, 2011 at 15:43 Comment(3)
It leads to link errors because the include you have to #include will not have converted before compilation via the typedef declarations all the int32... In other terms, during compilation all the above mentioned special types do not exist anymore - thus they are not present during linking either.Fulgurous
stdint.h was included into C99 in order to help programs portability. It is also available on Windows. See en.wikipedia.org/wiki/Stdint.hFulgurous
Should really be #include <cstdint> for C++ programs. That header isn't included with VS2008, but you can find a compatible file in several places on the 'net.Malvina
P
0

I'm guessing that uint8_t has been typedefed as unsigned char, hence why you're seeing that.

Prieto answered 1/1, 2011 at 15:41 Comment(3)
Looking at the source, no. uint8_t is typedef for UINT8.Breakthrough
hm.. I am not sure but uint8_t belongs to stdint.h which purpose is to abstract away from primitive types which might in turn be different in different platforms.Cuddle
The library I'm working with has include file, which differentiate between build environments. If it's windows it defines all int types manually, if Linux it includes stdint.h and inttypes.hBreakthrough
A
0

Try compiling with

template void my_object::func(int64_t value) { ... }
template void my_object::func(uint64_t value) { ... }
template void my_object::func(uint32_t value) { ... }
template void my_object::func(uint16_t value) { ... }
template void my_object::func(uint8_t value) { ... }

fixed my problem with a similar issues

Anuradhapura answered 6/11, 2019 at 21:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.