-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unresolved external symbol "unsigned char __cdecl sbepp::detail::byteswap<unsigned char>(unsigned char)" #69
Comments
Interesting, seems the issue is in this section: https://github.com/OleksandrKvl/sbepp/blob/main/sbepp/src/sbepp/sbepp.hpp#L569-L576. MSVC somehow can't figure out from that if-condition that |
Try constexpr: if constexpr((E != endian::native) && (sizeof(T) != 1))
{
value = from_unsigned<T>{}(byteswap(to_unsigned(value)));
} At least that might be a workaround for our case as we've migrated to C++17 |
It will work for C++17 but not for C++11/14. |
Can you please check if the fix from PR works for you? I don't have access to MSVC compiler at the moment. |
As far as you have the template specialization for the 1-byte variables, do you still need that |
Removing |
Maybe better then to specialize the
|
Actually two specializations are needed: #include <type_traits>
#include <cstring>
enum endianness
{
little,
big,
};
constexpr auto NativeEndianness = endianness::little;
template<endianness E, typename T>
typename std::enable_if<E == NativeEndianness || sizeof(T) == 1>::type
set_primitive(void* addr, T v)
{
memcpy(addr, &v, sizeof(v));
}
template<endianness E, typename T>
typename std::enable_if<E != NativeEndianness && sizeof(T) != 1>::type
set_primitive(void* addr, T v)
{
auto const reversed = byteswap(v);
memcpy(addr, &reversed, sizeof(reversed));
}
char buf[120];
int main()
{
set_primitive<endianness::little>(buf, '1');
set_primitive<endianness::little>(buf, 1);
set_primitive<endianness::big>(buf, '1');
set_primitive<endianness::big>(buf, 1);
} |
that will only cause code duplication without any benefits, existing PR fixes the problem with only a couple of lines. |
Ok, up to you. I will try to verify your change as quickly as possible. I need to switch from Conan to Git repo somehow. |
Actually the way as I proposed is better, as it makes code more clear. It removes |
That works. Thank you very much |
Good, then I'm merging, thank you for reporting and testing the fix! |
@ujos do you want this fix in Conan ASAP? I'm thinking if I should wait till the end of the week, maybe you'll discover more MSVC-related problems. |
Actually, I was wrong about avoidance of |
That was the only issue I found so far. That would be just great to have a release in the Conan next week. |
When I build my application based on sbepp v1.3.0 with Visual Studio 2019/2022, I get a link time error:
Looks like the problem is caused by the following declaration without the definition:
sbepp\sbepp.hpp:(464)
g++ 11/12 compiles the code just fine.
Please let me know if you need a full source code to reproduce the issue.
The text was updated successfully, but these errors were encountered: