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

See for more information

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

# Patch from commit a69dfe63bc26c12fd2786aec9239076997110315
  set_source_files_properties(${tests_files} PROPERTIES COMPILE_FLAGS "-Wno-narrowing")

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

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: Logo

You are commenting using your 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