simulton / QSchematic

A library that allows creating diagrams such as flowcharts or even proper engineering schematics within a Qt application.
https://simulton.com
MIT License
231 stars 60 forks source link

`requires` error during compilation #54

Closed LIU-Yinyi closed 8 months ago

LIU-Yinyi commented 8 months ago

When I built the project following the document, the error as follows was triggered. My GCC version is 9.4.0 and it should support C++17 and C++20 according to the official documentation. Other mentioned dependencies such as QT5.15 and GPDS have already been installed. requires seems like a feature since C++20. I tried modifying the CMakeLists.txt within qschematic to adapt to C++20 but this error still existed. Could you advise what action I should further do to solve this problem? Thank you.

/dir/qt/qschematic/build/_deps/gpds-src/lib/include/gpds/serialize.hpp: In function ‘std::pair<bool, std::__cxx11::basic_string<char> > gpds::to_stream(std::ostream&, const Object&, std::string_view)’:
/dir/qt/qschematic/build/_deps/gpds-src/lib/include/gpds/serialize.hpp:49:23: error: ‘requires’ was not declared in this scope
   49 |         if constexpr (requires { obj.to_container(); })
      |                       ^~~~~~~~
/dir/qt/qschematic/build/_deps/gpds-src/lib/include/gpds/serialize.hpp:49:31: error: expected ‘)’ before ‘{’ token
   49 |         if constexpr (requires { obj.to_container(); })
      |                      ~        ^~
      |                               )
/dir/qt/qschematic/build/_deps/gpds-src/lib/include/gpds/serialize.hpp: In function ‘std::pair<bool, std::__cxx11::basic_string<char> > gpds::from_stream(std::istream&, Object&, std::string_view)’:
/dir/qt/qschematic/build/_deps/gpds-src/lib/include/gpds/serialize.hpp:118:23: error: ‘requires’ was not declared in this scope
  118 |         if constexpr (requires{ obj.from_container(gpds::container{}); }) {
      |                       ^~~~~~~~
/dir/qt/qschematic/build/_deps/gpds-src/lib/include/gpds/serialize.hpp:118:31: error: expected ‘)’ before ‘{’ token
  118 |         if constexpr (requires{ obj.from_container(gpds::container{}); }) {
      |                      ~        ^
      |                               )
make[2]: *** [qschematic/CMakeFiles/qschematic-shared.dir/build.make:76: qschematic/CMakeFiles/qschematic-shared.dir/qschematic-shared_autogen/mocs_compilation.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:293: qschematic/CMakeFiles/qschematic-shared.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
Tectu commented 8 months ago

The compilation error(s) you're getting are definitely only related to the GPDS dependency (https://github.com/simulton/gpds). Could you please share the version of GPDS you're using and which compiler you're using?

On a side note: I'll update the QSchematic readme to reflect the need for a C++20 compiler.

LIU-Yinyi commented 8 months ago

The compilation error(s) you're getting are definitely only related to the GPDS dependency (https://github.com/simulton/gpds). Could you please share the version of GPDS you're using and which compiler you're using?

On a side note: I'll update the QSchematic readme to reflect the need for a C++20 compiler.

Thanks for your prompt reply. I enabled the option QSCHEMATIC_DEPENDENCY_GPDS_DOWNLOAD and it was supposed to be the latest 1.8.1 version. It seems that no explicit definition about C++ standard version in the CMakeLists.txt of GPDS project.

Tectu commented 8 months ago

It seems that no explicit definition about C++ standard version in the CMakeLists.txt of GPDS project.

It's set as part of target_compile_features() here: https://github.com/simulton/gpds/blob/42f7b76a42fdc7068ca779c6f5bed1593e08e1dc/lib/CMakeLists.txt#L48 This transitively makes it to consuming projects (such as QSchematic). Therefore, consuming GPDS 1.8.1 will automatically set C++20 as the required standard in the QSchematic targets (via the generated gpds-targets.cmake when consuming a GPDS installation and just via regular target properties when consuming a non-installed version).

Can you tell us exactly which compiler you're using?

LIU-Yinyi commented 8 months ago

Can you tell us exactly which compiler you're using?

>>> g++ --version
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.

>>> cmake -B build
-- The CXX compiler identification is GNU 9.4.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

Should I update it to a newer version?

Tectu commented 8 months ago

AFAIK GCC only supports concepts starting with version 10: https://en.cppreference.com/w/cpp/compiler_support Personally, I know that the library works with GCC 12 and 13 (10 and 11 also used to work, but haven't tested that in a while).

LIU-Yinyi commented 8 months ago

AFAIK GCC only supports concepts starting with version 10: https://en.cppreference.com/w/cpp/compiler_support Personally, I know that the library works with GCC 12 and 13 (10 and 11 also used to work, but haven't tested that in a while).

Many thanks for your patience and guidance! @Tectu For other developers who would encounter this problem, kindly update the version your gcc and g++ to 10 or above:

# suppose developing on Ubuntu
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa -y
sudo apt update

# the version can be 10/11/12/13
sudo apt install g++-10 gcc-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10

# update the priority of the gcc/g++ 10 or above
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
LIU-Yinyi commented 8 months ago

The problem has been resolved.