Build fails on MinGW under WSL1
../ext/kaitai_rt/kaitai/kaitaistream.cpp:21:10: fatal error: endian.h: No such file or directory
21 | #include <endian.h>
It appears this has been an issue on MacOS before. Is Windows even supported?
Compiling with Mingw W64 under WSL1.
Going to try using https://github.com/mikepb/endian.h/blob/master/endian.h to see if this "fixes" it but it'd be nice if there was explicit support for Windows.
EDIT: Yes, but then there's a missing byteswap.h.
Welp I added a bunch of hacks and now I'm getting a duplicate symbol linker error:
/usr/bin/x86_64-w64-mingw32-ld: /usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/libgcc_eh.a(unwind-seh.o):(.text+0x3d0): multiple definition of `_Unwind_Resume'; ext/kaitai_rt/libkaitai_struct_cpp_stl_runtime.dll.a(d000015.o):(.text+0x0): first defined here
Looks like Kaitai can't be used on windows, or at least, not on MinGW.
Is Windows even supported?
Yes, but the runtime is currently only adapted for the Microsoft Visual C++ compiler to work out of the box. See kaitaistream.cpp:
https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime/blob/cb09b3a84c7e905c6a3fecfe9617cf864d9af781/kaitai/kaitaistream.cpp#L12-L23
but it'd be nice if there was explicit support for Windows.
I agree. Pull requests are welcome - if you figure out what to add to the top of kaitaistream.cpp so that the runtime library works seamlessly also on other Windows compilers than MSVC, I'll be happy to accept your contribution :)
Going to try using https://github.com/mikepb/endian.h/blob/master/endian.h
EDIT: Yes, but then there's a missing
byteswap.h.
You have presumably already figured out until now where to get both endian.h and byteswap.h, but here's what I used for testing on Windows (https://github.com/kaitai-io/kaitai_struct/pull/738#issue-408877598):
It's tested under Windows 10 64-bit with the
g++compiler 8.3.0. It worked, but I had to getendian.handbyteswap.hfrom the internet, because they're not available on Windows and the C++ runtime relies on them. Maybe the runtime should be fixed to support Windows out-of-the-box as well.
Welp I added a bunch of hacks and now I'm getting a duplicate symbol linker error:
I think this is more related to MinGW than the KS C++/STL runtime library itself. Do you use an up-to-date MinGW compiler? Does this happen also on other projects?
If I search for this error, it seems that people resolve it by passing some additional command-line options when compiling.
For me adding || defined(MINGW32) next to the _MSC_VER worked on Mingw on Windows:
include <kaitai/kaitaistream.h>
#if defined(__APPLE__)
#include <machine/endian.h>
#include <libkern/OSByteOrder.h>
#define bswap_16(x) OSSwapInt16(x)
#define bswap_32(x) OSSwapInt32(x)
#define bswap_64(x) OSSwapInt64(x)
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#elif defined(_MSC_VER) || defined(__MINGW32__) // !__APPLE__
#include <stdlib.h>
#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
#define __BYTE_ORDER __LITTLE_ENDIAN
#define bswap_16(x) _byteswap_ushort(x)
#define bswap_32(x) _byteswap_ulong(x)
#define bswap_64(x) _byteswap_uint64(x)
#else // !__APPLE__ or !_MSC_VER
#include <endian.h>
#include <byteswap.h>
#endif