Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling errors with Ubuntu22.04 #364

Closed
Alizyt opened this issue Apr 14, 2023 · 8 comments
Closed

Compiling errors with Ubuntu22.04 #364

Alizyt opened this issue Apr 14, 2023 · 8 comments

Comments

@Alizyt
Copy link

Alizyt commented Apr 14, 2023

I'm having a bunch of compiling error when using the single header file on Ubuntu 22.04.2 w/ gcc11, most relates to std::chars_format.
Is it now fully supported?

@biojppm
Copy link
Owner

biojppm commented Apr 14, 2023

I tried it, and it works flawlessly, without any compiler warnings:

git clone --recursive https://github.com/biojppm/rapidyaml
cd rapidyaml/samples/singleheader && ./run.sh

The result is

+ cfg=Release
++ dirname ./run.sh
+ cd .
+ cmake -S . -B ./build/Release -DCMAKE_BUILD_TYPE=Release
-- The CXX compiler identification is GNU 11.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /usr/bin/python3.10 (found version "3.10.6") found components: Interpreter
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jpmag/proj/rapidyaml/samples/singleheader/build/Release
+ cmake --build ./build/Release --config Release --target run
[ 33%] /usr/bin/python3.10 /home/jpmag/proj/rapidyaml/samples/singleheader/../../tools/amalgamate.py /home/jpmag/proj/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp
[ 66%] Building CXX object CMakeFiles/ryml-quickstart.dir/home/jpmag/proj/rapidyaml/samples/quickstart.cpp.o
[100%] Linking CXX executable ryml-quickstart
[100%] Built target ryml-quickstart
/home/jpmag/proj/rapidyaml/samples/quickstart.cpp:187: OK! tree.is_map(root_id)
/home/jpmag/proj/rapidyaml/samples/quickstart.cpp:188: OK! tree.is_seq(bar_id)
/home/jpmag/proj/rapidyaml/samples/quickstart.cpp:194: OK! root.is_map()
.... # etc

This defaults on cxx_std_11. It works just the same if I set the standard to 17 or 20 (by changing the cmake file).

I suspect something else is at play. How are you compiling it? Do you have any special flags enabled?

@Alizyt
Copy link
Author

Alizyt commented Apr 18, 2023

Hi @biojppm,

Thank you for looking into this. I've tried the sample code compiling on my system and it passed as well. After a little bit further digging into, I found the issue relates to the other header file <boost/format.hpp> included in my project, and the include order matters. I can simply reproduce the error by including <boost/format.hpp> before <ryml_all.hpp> within quickstart.cpp, see diff as below:

diff --git a/samples/quickstart.cpp b/samples/quickstart.cpp
index 0652f9f..785e3ef 100644
--- a/samples/quickstart.cpp
+++ b/samples/quickstart.cpp
@@ -23,6 +23,8 @@

 //-----------------------------------------------------------------------------

+#include <boost/format.hpp>
+
 // ryml can be used as a single header, or as a simple library:
 #if defined(RYML_SINGLE_HEADER) // using the single header directly in the executable
     #define RYML_SINGLE_HDR_DEFINE_NOW

And then the compiling errors will be as below:

+ cfg=Release
++ dirname ./run.sh
+ cd .
+ cmake -S . -B ./build/Release -DCMAKE_BUILD_TYPE=Release
-- Configuring done (0.1s)
-- Generating done (0.1s)
-- Build files have been written to: /home/dev/ali/rapidyaml/samples/singleheader/build/Release
+ cmake --build ./build/Release --config Release --target run
[ 33%] Building CXX object CMakeFiles/ryml-quickstart.dir/home/dev/ali/rapidyaml/samples/quickstart.cpp.o
In file included from /home/dev/ali/rapidyaml/samples/quickstart.cpp:42:
/home/dev/ali/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp:10781:42: error: ‘chars_format’ is not a member of ‘std’; did you mean ‘fast_float::chars_format’?
10781 | typedef enum : std::underlying_type<std::chars_format>::type {
      |                                          ^~~~~~~~~~~~
In file included from /home/dev/ali/rapidyaml/samples/quickstart.cpp:42:
/home/dev/ali/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp:7428:6: note: ‘fast_float::chars_format’ declared here
 7428 | enum chars_format {
      |      ^~~~~~~~~~~~
In file included from /home/dev/ali/rapidyaml/samples/quickstart.cpp:42:
/home/dev/ali/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp:10781:54: error: template argument 1 is invalid
10781 | typedef enum : std::underlying_type<std::chars_format>::type {
      |                                                      ^
/home/dev/ali/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp:10781:57: error: expected ‘{’ before ‘type’
10781 | typedef enum : std::underlying_type<std::chars_format>::type {
      |                                                         ^~~~
/home/dev/ali/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp:10781:57: error: typedef ‘c4::type’ is initialized (use ‘decltype’ instead)
/home/dev/ali/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp:10783:5: error: ‘FTOA_FLOAT’ was not declared in this scope; did you mean ‘MAXFLOAT’?
10783 |     FTOA_FLOAT = static_cast<std::underlying_type<std::chars_format>::type>(std::chars_format::fixed),
      |     ^~~~~~~~~~
      |     MAXFLOAT
/home/dev/ali/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp:10783:56: error: ‘chars_format’ is not a member of ‘std’; did you mean ‘fast_float::chars_format’?
10783 |     FTOA_FLOAT = static_cast<std::underlying_type<std::chars_format>::type>(std::chars_format::fixed),
      |                                                        ^~~~~~~~~~~~
In file included from /home/dev/ali/rapidyaml/samples/quickstart.cpp:42:
/home/dev/ali/rapidyaml/samples/singleheader/../../src_singleheader/ryml_all.hpp:7428:6: note: ‘fast_float::chars_format’ declared here
 7428 | enum chars_format {
      |      ^~~~~~~~~~~~
In file included from /home/dev/ali/rapidyaml/samples/quickstart.cpp:42:
...... # etc

@biojppm
Copy link
Owner

biojppm commented May 5, 2023

Thanks - with your description I now see the error.

It has to do with the amalgamated header, where for some reason std::chars_format is used when it should not be. This only happens with the single header; for example the add_subdirectory sample runs without problems.

I guess some macro in the boost header is throwing off the preprocessor code for charconv method selection, but I have to investigate this.

@biojppm
Copy link
Owner

biojppm commented May 5, 2023

Actually, it was down to a filtered #include <charconv> in the amalgamated header. This was fixed (I hope) by updating to the fixed c4core version.

Can you confirm that the current master fixes your problem?

@Alizyt
Copy link
Author

Alizyt commented May 17, 2023

Sorry for a delayed response, @biojppm.
I just tried the latest master on my env, and it's working now! BRAVO!!!
One more thing is that I noticed the newly generated single header file is pretty different from the previous one, with more than 3000 lines diff, is it expected?

@biojppm
Copy link
Owner

biojppm commented May 17, 2023

Yes, there was an update of the fastfloat library, and also more work on the c4core.

@biojppm
Copy link
Owner

biojppm commented May 25, 2023

Closing now. Thanks for reporting!

@biojppm biojppm closed this as completed May 25, 2023
@Alizyt
Copy link
Author

Alizyt commented Jun 6, 2023

You're very welcome😄

johnbartholomew added a commit to johnbartholomew/jsonnet that referenced this issue Mar 6, 2024
When building with bundled JSON and bundled RapidYAML, the build works.
However, when building with system-provided JSON and bundled RapidYAML, the build
fails due to many things not being defined. It seems these are supposed to come
from the standard <charconv> header, but RapidYAML 0.5.0 release erroneously
strips that include in its single-file amalgamation. See RapidYAML issue

biojppm/rapidyaml#364 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants