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

3.15.x doesn't build on FreeBSD cause of missing endian.h #8373

Open
dmilith opened this issue Mar 4, 2021 · 9 comments
Open

3.15.x doesn't build on FreeBSD cause of missing endian.h #8373

dmilith opened this issue Mar 4, 2021 · 9 comments
Labels
platform related

Comments

@dmilith
Copy link

@dmilith dmilith commented Mar 4, 2021

What version of protobuf and what language are you using?
Version: 3.15.4
Language: C++

What operating system (Linux, Windows, ...) and version?
FreeBSD x86_64, v12.2

What runtime / compiler are you using (e.g., python version or gcc version)
clang 10.0.1

What did you do?
Either autotools build with ./configure && make or cd cmake && cmake ../ … && make

What did you expect to see
Properly built library

What did you see instead?

A lot of errors like this in multiple files, example:

src/google/protobuf/stubs/port.h:63:10: fatal error: 'endian.h' file not found
#include <endian.h>  // __BYTE_ORDER

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment
No. It's a pretty standard environment.

@dmilith dmilith changed the title Doesn't build on FreeBSD 3.15.x doesn't build on FreeBSD cause of missing endian.h Mar 4, 2021
@dmilith
Copy link
Author

@dmilith dmilith commented Mar 5, 2021

This can be hacked by:

sed -i '' -e 's|endian.h|machine/endian.h|g' src/google/protobuf/*.h src/google/protobuf/stubs/*.h src/google/protobuf/io/*.h

So it's just wrong include path on FreeBSD. After that hack project builds w/o issues.

@Mizux
Copy link
Contributor

@Mizux Mizux commented Mar 5, 2021

Strange FreeBSD seems already supported...

#ifdef __APPLE__
#include <machine/endian.h> // __BYTE_ORDER
#elif defined(__FreeBSD__)
#include <sys/endian.h> // __BYTE_ORDER
#else
#include <endian.h> // __BYTE_ORDER
#endif

FYI in google/or-tools we are using (and we test using github macos runner (ed provide virtualbox support), and a Vagrant FreeBSD box)

#if (defined(__APPLE__) || defined(__FreeBSD__)) && defined(__GNUC__)
#include <machine/endian.h>
#elif !defined(_MSC_VER)
#include <endian.h>
#endif

@dmilith
Copy link
Author

@dmilith dmilith commented Mar 9, 2021

Well, it looks like protobuf/stubs/port.h should have:

#ifdef __APPLE__ || defined(__FreeBSD__) 
 #include <machine/endian.h>  // __BYTE_ORDER 
 #else 
 #include <endian.h>  // __BYTE_ORDER 
 #endif 

@scddev
Copy link
Contributor

@scddev scddev commented May 18, 2021

Same behavior also on AIX and SunOS:

-bash-4.4$ cmake -S cmake -B _build -Dprotobuf_BUILD_TESTS=OFF
-- 
-- 3.17.0.0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/foo/protobuf-3.17.0/_build
-bash-4.4$ cmake --build _build
gmake[1]: Entering directory '/home/foo/protobuf-3.17.0/_build'
gmake[2]: Entering directory '/home/foo/protobuf-3.17.0/_build'
Scanning dependencies of target libprotobuf-lite
gmake[2]: Leaving directory '/home/foo/protobuf-3.17.0/_build'
gmake[2]: Entering directory '/home/foo/protobuf-3.17.0/_build'
[  0%] Building CXX object CMakeFiles/libprotobuf-lite.dir/home/foo/protobuf-3.17.0/src/google/protobuf/any_lite.cc.o
In file included from /home/foo/protobuf-3.17.0/src/google/protobuf/stubs/common.h:48:0,
                 from /home/foo/protobuf-3.17.0/src/google/protobuf/any.h:36,
                 from /home/foo/protobuf-3.17.0/src/google/protobuf/any_lite.cc:31:
/home/foo/protobuf-3.17.0/src/google/protobuf/stubs/port.h:65:37: fatal error: endian.h: No such file or directory
 #include <endian.h>  // __BYTE_ORDER
                                     ^
compilation terminated.
gmake[2]: *** [CMakeFiles/libprotobuf-lite.dir/build.make;63: CMakeFiles/libprotobuf-lite.dir/home/foo/protobuf-3.17.0/src/google/protobuf/any_lite.cc.o] Error 1
gmake[2]: Leaving directory '/home/foo/protobuf-3.17.0/_build'
gmake[1]: *** [CMakeFiles/Makefile2;73: CMakeFiles/libprotobuf-lite.dir/all] Error 2
gmake[1]: Leaving directory '/home/foo/protobuf-3.17.0/_build'
gmake: *** [Makefile;130: all] Error 2
-bash-4.4$ uname
AIX

@Mizux
Copy link
Contributor

@Mizux Mizux commented May 19, 2021

@scdded do you have machine/endian.h or sys/endian.h on your system ?

@scddev
Copy link
Contributor

@scddev scddev commented May 19, 2021

@Mizux endian.h does not exist on AIX (sys/machine.h) and SunOS (sys/isa_defs.h)

@elharo elharo added the platform related label Aug 26, 2021
@gdharley
Copy link

@gdharley gdharley commented Sep 23, 2021

I can confirm the same error on AIX 7.1.
Is there a work around?

@scddev
Copy link
Contributor

@scddev scddev commented Sep 23, 2021

@gdharley yes, this could be fixed by using sys/machine.h instead of endian.h.

You will end up with adding the following snippet to src/google/protobuf/stubs/port.h and src/google/protobuf/io/coded_stream.h before the else to include endian.h:

#elif defined(_AIX) || defined(__TOS_AIX__)
#include <sys/machine.h>  // BYTE_ORDER

@scddev
Copy link
Contributor

@scddev scddev commented Oct 6, 2021

I have created a PR #9065 to fix AIX and SunOS, but seems the corporate CLA is not in effect yet.

acozzette pushed a commit that referenced this issue Oct 11, 2021
* fix includes for AIX and SunOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform related
Projects
None yet
Development

No branches or pull requests

5 participants