on macOS, there is no byteswap.h, so trying to build 1.0.13 fails with this error:
libemf.cpp:75:10: fatal error: 'byteswap.h' file not found
#include <byteswap.h>
^~~~~~~~~~~~
This is with system-clang. Switching to gnu-gcc-11 gets the same error.
Using Fink, we have gnulib from 2023 that includes byteswap.h. Borrowing the header from that lets it build. But with a newer gnulib from 2025, the build fails like this:
In file included from libemf.cpp:75:
./byteswap.h:23:3: error: "Please include config.h first."
#error "Please include config.h first."
^
./byteswap.h:28:1: error: unknown type name '_GL_INLINE_HEADER_BEGIN'
_GL_INLINE_HEADER_BEGIN
^
./byteswap.h:34:1: error: expected unqualified-id
extern "C" {
^
./byteswap.h:113:1: error: use of undeclared identifier '_GL_INLINE_HEADER_END'
_GL_INLINE_HEADER_END
^
The config.h thing looks like a misdirection because the #error is inside this #if:
/* This file uses _GL_INLINE. */
#if !_GL_CONFIG_H_INCLUDED
#error "Please include config.h first."
#endif
So all related to GL_INLINE.
Is there another source of byteswap.h ?
It looks like bswap_32 is the only function used from byteswap.h. Is there an equivalent function on macOS? (https://man7.org/linux/man-pages/man3/bswap.3.html)
Searching gives changes like this:
Would need to #ifdef on
__APPLE__probably.https://stackoverflow.com/questions/41770887/cross-platform-definition-of-byteswap-uint64-and-byteswap-ulong
So I tried that, but if I put the following in place of the
#include <byteswap.h>down on line 75, I get errors about function definitions before '{' tokens.So I had to move the whole #include chunk to the very top after
#include <climits>I don't know if it would be more appropriate to check for byteswap.h in configure and check for other possibilities if not found rather than a straight #ifdefelse in the code
I have no recollection of why I put the #include in the middle of the
function; it seems dumb in retrospect. Your #ifdef/else at the top is OK
with me. I don't want to have to struggle with autotools anymore. I have no
way to test this on a mac, but if you send me a patch I'll apply it.
Are the new ARM-based macs run in little endian mode? Because the whole
bswap business is never invoked on little endian machines anyway.
On Fri, Apr 18, 2025 at 7:49 AM Hanspeter Niederstrasser nieder@users.sourceforge.net wrote:
Related
Bugs: #6
Yes, both the Arm and X86_64 Apple systems are little endian. Can we just trigger not to call byteswap or include it ifdef Apple ?
Not a C person, but looking at the code, I'm confused as to what it's actually doing. It goes into the DWORD swab, and checks if the system is bigEndian(). If not, then it returns a. Should that then exit and not run bswap_32(a)? Or am I misunderstanding and it'll always return both a and the swapped a?
I'm on x86_64, which is little endian, so I would expect it to not try to run bswap_32 (forgetting for the moment the header issue).
Shouldn't endianess be determined by configure and byteswap.h only included if the system is big-endiean? Usualy configure is used to determine endianess at compile time.
Or if you want to be specific to Apple clang, it has the following relefant defines to avoid including bytesswap.h?
Thanks for your suggestions. I will probably apply Hanspeter's #include change as that seems like the simplest way.
My patch to add
libkern/OSByteOrder.hon Apple is attached. It's pretty simplistic and only checks for__APPLE__. As Scott says, an autotools method (AC_C_BIGENDIAN) could be 'better' (for some definition of better), but it seems overkill for this and then having to maintain configure.ac, etc.Would it improve it to wrap the entire set of includes on an #ifdef for
__BIG_ENDIAN__(does gcc have this macro or just__ORDER_BIG_ENDIAN__)?The only thing I'm unclear on is why my x86_64 system (little endian) was originally even trying to include byteswap.h since it's after the
bigEndian()check in the code.The bigEndian() check is a run time check. The #include <byteswap.h> is always included by the precompiler before the compile phase. It would have to be excluded by an #IFDEF or some other precompiler flag along with removing the actual call to bswap_32 also with an #IFDEF compiler directive.</byteswap.h>
Hi Hanspeter and Scott: I have committed Hanspeter's patch to the repository (along with an update to the autotools/configure scripts). Please check that the svn HEAD (r101) compiles and passes regression on a macos machine. If it works, I'll make a release of 1.0.14 (if I can remember how, anyway).
I've been trying to remember why the endian-ness check is a run-time function and not a manifest attribute of the platform. But, I just can't recall what I was thinking in 2010 :-) I don't really want to have to update the autotools scripts.
Thanks for your input,
Allen