rapidjson
rapidjson copied to clipboard
Build Error with recent GCC of v1.1.0
When trying to rebuild rapidjson with gcc --version gcc (GCC) 13.2.1 20230801 (current on e.g. Archlinux)
The new GCC Version seems to throw some new Warnings causing the build to fail
/external/rapidjson/example/filterkeydom/filterkeydom.cpp:155:22: required from here /external/rapidjson/include/rapidjson/document.h:1952:24: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'rapidjson::GenericValue<rapidjson::UTF8<> >::Member' {aka 'struct rapidjson::GenericMember<rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator<> >'} with no trivial copy-assignment; use copy-assignment instead [-Werror=class-memaccess] 1952 | std::memcpy(m, members, count * sizeof(Member)); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /external/rapidjson/include/rapidjson/document.h:71:8: note: 'rapidjson::GenericValue<rapidjson::UTF8<> >::Member' {aka 'struct rapidjson::GenericMember<rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator<> >'} declared here 71 | struct GenericMember { | ^~~~~~~~~~~~~ . . . /external/rapidjson/example/filterkeydom/filterkeydom.cpp:155:22: required from here /external/rapidjson/include/rapidjson/document.h:1939:24: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class rapidjson::GenericValue<rapidjson::UTF8<> >' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Werror=class-memaccess] 1939 | std::memcpy(e, values, count * sizeof(GenericValue)); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /external/rapidjson/include/rapidjson/document.h:540:7: note: 'class rapidjson::GenericValue<rapidjson::UTF8<> >' declared here 540 | class GenericValue { | ^~~~~~~~~~~~ cc1plus: all warnings being treated as errors make[2]: *** [example/CMakeFiles/filterkeydom.dir/build.make:76: example/CMakeFiles/filterkeydom.dir/filterkeydom/filterkeydom.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:1051: example/CMakeFiles/filterkeydom.dir/all] Error 2 make: *** [Makefile:146: all] Error 2
my build commands are: echo "Running cmake Script" LANG=C cmake -DCMAKE_BUILD_TYPE=Debug -S ./ -B $builddir
echo "Building Executeable" LANG=C cmake --build $builddir --target all --clean-first
cmake version 3.27.7
I believe this compilation error was triggered by your project configuration, do you have -Werror
in your compile flags?
Just to clarify, that build is no project of mine - just clone rapidjson, create a build directory, start an out of source build of the CMakeLists.txt (https://github.com/Tencent/rapidjson/blob/master/CMakeLists.txt) supplied by rapidjson. Nothing more. no edit or patch by myself. 100% rapidjson sources and buildfiles.
Just to clarify, that build is no project of mine - just clone rapidjson, create a build directory, start an out of source build of the CMakeLists.txt (https://github.com/Tencent/rapidjson/blob/master/CMakeLists.txt) supplied by rapidjson. Nothing more. no edit or patch by myself. 100% rapidjson sources and buildfiles.
Ok, I see that. If you're stuck with v1.1.0 release you should add -Wno-error=class-memaccess
to CXXFLAGS
for workaround. Anyway, this problem has been fixed in the master.
just tested, when I add -Wno-error=class-memaccess
, the compiler gets futher in code, but then another issue pops up:
/external/rapidjson/include/rapidjson/internal/regex.h:301:21: error: this statement may fall through [-Werror=implicit-fallthrough=]
301 | if (!CharacterEscape(ds, &codepoint))
| ^~
You should add -Wno-error=...
for each error then, or patch CMakeFile.txt
to not append -Werror
to CXXFLAGS
.
Yes, thats obvious. Already implemented it that way as a temporary fix. But for production software shipped to customers I would prefer a official release, that builds ok out of the box. Just googled it (and not digged any deeper), but it seems the warnings can be resolved in most / all cases with correct casts? To me, that seems to be the cleanest solution.
You have to use the master, v1.1.0 was released 7 years ago. All these problems have already been fixed, and -Werror
in CMakeFiles.txt
applies only to rapidjson itself.
You can skip any compilation in v1.1.0 when installing from cmake by using this options: -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF