error: call to non-'constexpr' function 'std::mutex::mutex() constexpr WrappedMutex() {}
What version of protobuf and what language are you using?
Version: v3.19.1 Language: C++
What operating system (Linux, Windows, ...) and version?
Windows
What runtime / compiler are you using (e.g., python version or gcc version)
xtensa-esp32-elf-g++.exe (crosstool-NG esp-2021r1) 8.4.0 toolchain: ESP-IDF v4.3.1
What did you do?
- I downloaded https://github.com/MarcGeh/esp32-cpp-protobuf example on how to port protobuf to esp32. (compiles OK)
- I tried to update protobuf source to 3.19.1. (removing and copying the proper protobuf folder @ components AND recompiling main\proto\test.proto with protoc 3.19.1)
- run
idf.py build - Compilation throws
In file included from ../components/protobuf/src/google/protobuf/descriptor.h:66,
from ../components/protobuf/src/google/protobuf/generated_message_reflection.h:45,
from ../components/protobuf/src/google/protobuf/wrappers.pb.h:29,
from ../components/protobuf/src/google/protobuf/wrappers.pb.cc:4:
../components/protobuf/src/google/protobuf/stubs/mutex.h: In constructor 'constexpr google::protobuf::internal::WrappedMutex::WrappedMutex()':
../components/protobuf/src/google/protobuf/stubs/mutex.h:122:35: error: call to non-'constexpr' function 'std::mutex::mutex()'
constexpr WrappedMutex() {}
I compare the 3.15 to 3.19.1 version and the problematic line was on this line.
I edited this from
#if defined(__QNX__)
constexpr WrappedMutex() = default;
#else
constexpr WrappedMutex() {}
#endif
to
constexpr WrappedMutex() = default;
and tried to compile again, and It did perfectly.
I didn't try this with master branch. I could do som PR, but, since I don't wanna break anything related to QNX, I prefer just to report this issue here.
I uploaded the changes to my fork
@fbucafusco The more portable way to resolve this is by extending the #if to test for ESP_PLATFORM. ESP_PLATFORM is a definition set in ESP projects. See https://docs.espressif.com/projects/esp-idf/en/v4.4.2/esp32/api-guides/build-system.html#preset-component-variables
eg.
#if defined(__QNX__) || defined(ESP_PLATFORM)
WrappedMutex no longer exists.