drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.62k stars 1.12k forks source link

Anyone successfully compiling with C++ 20 modules? #1687

Closed CapitalMarkets closed 1 year ago

CapitalMarkets commented 1 year ago

Seems that there's something happening in the Drogon header files related to lazy loading that is preventing successful compilation for me.

Is anyone working with Drogon and Modules right now and able to provide hints/small example?

Many thanks

VladlenPopolitov commented 1 year ago

I tried month ago on MSVC++ 2022 (last update). IntelliSence went mad, showed warning about its experimental status with modules and got many errors, then compiler started generate errors. I gave in after one day of tries and removed all modules. Some errors lead to Drogon interior, but they are so unclear, that I could not find root cause of this errors.

CapitalMarkets commented 1 year ago

@VladlenPopolitov thank you very much for the feedback. Seems that some more work may be required in order to make the library fully compatible with modules.

I AM able to create individual modules that rely on Drogon. I AM NOT able to import any Drogon based module into another module also using Drogon.

I have a Linux/GCC environment that is otherwise compiling module based sources with no issues.

Seems some things are occurring at the Static Templates level I currently do not understand.

Controller Module [app3] trying to import Service Class Module [app4]

In file included
from c++/controller/app3.cc:7:

drogon/HttpController.h: In instantiation of ‘class drogon::HttpController<BCM>’:

c++/controller/app3.cc:29:26:   required from here
    drogon/HttpController.h:59:7: error: recursive lazy load
    59 | class HttpController : public DrObject<T>, public HttpControllerBase
       |       ^~~~~~~~~~~~~~
drogon/HttpController.h:59:7: fatal error: failed to load pendings for ‘drogon::DrObject’

compilation terminated.

C++ Main [app2] trying to import Controller Module [app3]

In file included
from /usr/include/c++/13/string:54,
from /usr/local/include/trantor/utils/Date.h:19,
from /usr/local/include/trantor/net/EventLoop.h:20,
from /usr/local/include/drogon/drogon.h:17,
from c++/app2.cc:3:

bits/basic_string.h: In substitution of ‘template<class _Alloc> using std::_RequireAllocator = typename std::enable_if<std::__is_allocator<_Alloc>::value, _Alloc>::type [with _Alloc = std::allocator<char>]’:
bits/basic_string.h:628:16:   required by substitution of ‘template<class> constexpr std::__cxx11::basic_string<char>::basic_string(char const*, const std::allocator<char>&) [with <template-parameter-1-1> = <missing>]’

c++/app2.cc:13:22:   required from here
    bits/basic_string.h:628:16: error: recursive lazy load
    628 |       template<typename = _RequireAllocator<_Alloc>>
        |                ^~~~~~~~
bits/basic_string.h:628:16: fatal error: failed to load pendings for ‘drogon::DrObject’

compilation terminated.

C++ Main [app2] trying to import Service Class Module [app4]

In file included
from /usr/include/c++/13/string:54,
from /usr/local/include/trantor/utils/Date.h:19,
from /usr/local/include/trantor/net/EventLoop.h:20,
from /usr/local/include/drogon/drogon.h:17,
from c++/app2.cc:3:

bits/basic_string.h: In substitution of ‘template<class _Alloc> using std::_RequireAllocator = typename std::enable_if<std::__is_allocator<_Alloc>::value, _Alloc>::type [with _Alloc = std::allocator<char>]’:
bits/basic_string.h:628:16: required by substitution of ‘template<class> constexpr std::__cxx11::basic_string<char>::basic_string(char const*, const std::allocator<char>&) [with <template-parameter-1-1> = <missing>]’

c++/app2.cc:13:22: required from here
    bits/basic_string.h:628:16: error: recursive lazy load
    628 |       template<typename = _RequireAllocator<_Alloc>>
        |                ^~~~~~~~
bits/basic_string.h:628:16: fatal error: failed to load pendings for ‘drogon::DrObject’

compilation terminated.

note: C++ Main is NOT a module but it touches drogon by loading the drogon config and executing drogon's run() method.

AmdRyZen commented 1 year ago

cpp 23

image
VladlenPopolitov commented 1 year ago

According to C++ compiler support report https://en.cppreference.com/w/cpp/compiler_support (C++23 section) gcc, Clang and MSVC has only partial support of the modules, the remaining compilers do not have any support for modules. We have to wait with the usage of modules feature, when it will be implemented by compiler manufacturers.

CapitalMarkets commented 1 year ago

@VladlenPopolitov thanks for making things clearer... will keep an eye on the next gcc releases for support.