-
Notifications
You must be signed in to change notification settings - Fork 115
Description
The output of the amalgamate.py script produces a file which contains all instances of #include <stdarg.h>
commented out, except for the first one. This would be fine except that the first instance of #include <stdarg.h>
is inside a #ifdef C4CORE_SINGLE_HDR_DEFINE_NOW
block, but the second #include <stdarg.h>
(which is imported from src/c4/yml/parse.hpp) is not within a #ifdef C4CORE_SINGLE_HDR_DEFINE_NOW
or #ifdef RYML_SINGLE_HDR_DEFINE_NOW
block.
Therefore, when including the amalgamated output into a file without a preceding #define RYML_SINGLE_HDR_DEFINE_NOW
, the va_list
symbol is used without being declared, and produces an error (on at least some compilers). This is of course regardless of whether or not another compilation unit included the amalgamated output with RYML_SINGLE_HDR_DEFINE_NOW
defined, since it's a compilation error, not a linker error.
On the arm-none-eabi-gcc toolchain, I get this error, but compiling with clang++ 13 seems to work. I don't know the reason for the difference, but I'm guessing it's why this hasn't been detected until now.
Here's an easy way to replicate: (this is assuming the gcc-arm embedded toolchain 10.3 is installed and on $PATH):
git clone --recursive https://github.com/biojppm/rapidyaml
python3 rapidyaml/tools/amalgamate.py > ryml_all.hpp
echo "#include \"ryml_all.hpp\"" > test.cpp
arm-none-eabi-g++ -std=c++20 -c test.cpp -o test.o
Produces this error:
In file included from test.cpp:1:
ryml_all.hpp:20716:59: error: 'va_list' has not been declared
20716 | int _fmt_msg(char *buf, int buflen, const char *msg, va_list args) const;
| ^~~~~~~
Including <stdarg.h>
before ryml_all.hpp
works:
cat <<EOF > test2.cpp
#include <stdarg.h>
#include "ryml_all.hpp"
EOF
arm-none-eabi-g++ -std=c++20 -c test2.cpp -o test2.o
I would assume all standard library headers will have include guards, so I'm guessing the reason to ignore duplicate includes is to speed up compile time when using the amalgamated header? I can see it being tricky to get the python script to detect which #includes
are within #ifdef
blocks, and comment out accordingly, so I don't have a proposal for an easy, general solution. It's not a difficult work-around to include <stdarg.h>
manually. But I did want to bring it up since it might help someone else also using this project in the single-header method with the gcc arm compiler (since it is, IMO an excellent tool for using yaml on embedded systems).
Thanks for you hard work on this project.