--- src/google/protobuf-c/protobuf-c.c
+++ src/google/protobuf-c/protobuf-c.c
@@ -36,6 +36,17 @@
 #include <stdlib.h>                     /* for abort(), malloc() etc */
 #include <string.h>                     /* for strlen(), memcpy(), memmove() */
 
+#include <endian.h>
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define IS_BIG_ENDIAN 1
+#undef  IS_LITTLE_ENDIAN
+#else
+#error unsupported byte order!
+#endif
+
 #ifndef PRINT_UNPACK_ERRORS
 #define PRINT_UNPACK_ERRORS              1
 #endif
