Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

Cannot use in CLang C++ 20 #178

Open ctigrisht opened 1 year ago

ctigrisht commented 1 year ago

I am trying to use this in a CLang C++ 20 in visual studio 2022 project and I get errors, it works fine with Microsoft's compiler

image

eao197 commented 1 year ago

Hi!

Can you provide a description how to reproduce your problem?

ctigrisht commented 1 year ago

Hi!

Can you provide a description how to reproduce your problem?

Hey, I created a windows only C++ project in VS 2022. I tried installing from vcpkg first, using vcpkg install restinio, it gave the the error so I just cloned source code and put it inside 'Libraries' folder and included all.hpp.

I then create some code in main:

// other includes
#include "Libraries/restinio/all.hpp"

int main()
{
    auto port = 5690;
    auto address = "localhost";
    restinio::run(
        restinio::on_thread_pool(2)
        .port(port)
        .address(address)
        .request_handler([](auto req) {
            return req->create_response().set_body("Hello, World!").done();
            })
    );

    return 0;
}

The above code works fine with Microsoft compiler, but not clang. No errors in the code tho, only his lld-link

EDIT: It doesn't work with any CLang C++ version, not just 20

image

eao197 commented 1 year ago

Thanks for an explanation.

RESTinio itself is a header-only project, but it requires at least one dependency that should be compiled and then linked to the resulting executable: http_parser. fmtlib can be used as a header only or as a compiled library.

I suppose that when you build your example by using VC++ then some pragma lib in http_parser/fmtlib are taken into the account by the compiler/linker. In the case of clang you have to add http_parser and fmtlib to your project.

ctigrisht commented 1 year ago

add http_parser and fmtlib to your project

Do you mean link it within clang or embed it as source?

eao197 commented 1 year ago

I mean that you have to compile and link http_parser. You can do it as a separate library or by including its source into your project.

BTW, you can found more information about building RESTinio here: https://stiffstream.com/en/docs/restinio/0.6/obtaining.html#build

PS. I don't use VisualStudio and don't know how to use VisualStudio projects. I hope VisualStudio supports CMakeLists.txt files.