Skip to content
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

Build fails on MinGW under WSL1 #44

Open
Qix- opened this issue Jul 27, 2021 · 3 comments · May be fixed by #45
Open

Build fails on MinGW under WSL1 #44

Qix- opened this issue Jul 27, 2021 · 3 comments · May be fixed by #45

Comments

@Qix-
Copy link

Qix- commented Jul 27, 2021

../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.

@Qix-
Copy link
Author

Qix- commented Jul 27, 2021

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.

@generalmimon
Copy link
Member

generalmimon commented Jul 28, 2021

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:

#elif defined(_MSC_VER) // !__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

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 (kaitai-io/kaitai_struct#738 (comment)):

It's tested under Windows 10 64-bit with the g++ compiler 8.3.0. It worked, but I had to get endian.h and byteswap.h from 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.

@PeterWendt
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants