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

Add support for mingw and fix signedness compare warning #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PeterWendt
Copy link

@PeterWendt PeterWendt commented Sep 15, 2021

The || defined(__MINGW32__) makes it possible to compile with MinGw on Windows

additionally changing the type of got_len from int to size_t fixes the wsigncomparewarning that occurs

Closes #44

Copy link
Member

@generalmimon generalmimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The || defined(__MINGW32__) makes it possible to compile with MinGw on Windows

This doesn't work on my machine:

pp@DESKTOP-89OPGF3 MINGW64 /c/temp/cpp-test/runtime-mingw
$ head -n 17 /c/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp
#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)

pp@DESKTOP-89OPGF3 MINGW64 /c/temp/cpp-test/runtime-mingw
$ g++ -fmax-errors=3 -Wall -pedantic -std=c++11 -I/c/temp/kaitai_struct/runtime/cpp_stl/ -DKS_STR_ENCODING_NONE -o main main.cpp gif.cpp /c/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp: In member function 'int16_t kaitai::kstream::read_s2be()':
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp:17:21: error: '_byteswap_ushort' was not declared in this scope
   17 | #define bswap_16(x) _byteswap_ushort(x)
      |                     ^~~~~~~~~~~~~~~~
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp:118:9: note: in expansion of macro 'bswap_16'
  118 |     t = bswap_16(t);
      |         ^~~~~~~~
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp: In member function 'int32_t kaitai::kstream::read_s4be()':
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp:18:21: error: '_byteswap_ulong' was not declared in this scope
   18 | #define bswap_32(x) _byteswap_ulong(x)
      |                     ^~~~~~~~~~~~~~~
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp:127:9: note: in expansion of macro 'bswap_32'
  127 |     t = bswap_32(t);
      |         ^~~~~~~~
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp: In member function 'int64_t kaitai::kstream::read_s8be()':
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp:19:21: error: '_byteswap_uint64' was not declared in this scope
   19 | #define bswap_64(x) _byteswap_uint64(x)
      |                     ^~~~~~~~~~~~~~~~
C:/temp/kaitai_struct/runtime/cpp_stl/kaitai/kaitaistream.cpp:136:9: note: in expansion of macro 'bswap_64'
  136 |     t = bswap_64(t);
      |         ^~~~~~~~
compilation terminated due to -fmax-errors=3.

I got the g++ compiler via MinGW Installation Manager by installing the mingw32-gcc-g++-bin package (right in the Basic Setup tab).

@PeterWendt What compiler are you using, how do you invoke it and where did you get it? Is it possible that you are somehow including the headers from MSVC? Functions like _byteswap_ulong appear to be exclusively associated with the MSVC chain.


IMHO in the long run, it doesn't make sense to manage this logic in our code. It supports only a few platforms, we don't have any solid testing of where and whether it works correctly (so we rely on what users report to us), etc. It would be better to find a solid existing header file for this purpose (e.g. endianness.h, byteswap.h) and just use it.

@GreyCat GreyCat mentioned this pull request Jun 16, 2023
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 this pull request may close these issues.

Build fails on MinGW under WSL1
2 participants