Building protobuf with MinGW

Even if the documentation of the project doesn’t mention it, building protobuf with MinGW is easy when using CMake. The CMakeLists.txt is located in the “cmake” subdirectory.

I used following versions:

  • MinGW 7.2.0 (64 bit)
  • CMake 3.12.1
  • Protobuf 3.6.1

Two workarounds are however required with these versions:

Add “-DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON” to the CMake command line to avoid the error:

fatal error: stdlib.h: No such file or directory
#include_next 

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129 for more information

Also, you will need to apply this patch to cmake/tests.cmake:

# Patch from commit a69dfe63bc26c12fd2786aec9239076997110315
# https://github.com/protocolbuffers/protobuf/commit/a69dfe63bc26c12fd2786aec9239076997110315#diff-f9c045cbe267fdd0dfff7a28d4b5365e
if(MINGW)
  set_source_files_properties(${tests_files} PROPERTIES COMPILE_FLAGS "-Wno-narrowing")

  # required for tests on MinGW Win64
  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,16777216")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
  endif()

endif()
Advertisements
This entry was posted in C/C++. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s