r/cpp • • Mar 09 '23

Removed - Help Compiling CrowCPP on Windows and about to kms

[removed] — view removed post

0 Upvotes

7 comments sorted by

View all comments

5

u/delta_p_delta_x Mar 09 '23 edited Mar 09 '23

I have no issues with CrowCpp on Windows, using the x64-windows triplet and a fresh clone of vcpkg and a fresh install of the crow port. Here is what I did; perhaps it might help.

  1. Ensure you have Visual Studio 2022 with the Desktop Development with C++ workload installed. Or, get the Build Tools for Visual Studio 2022 and also install a similar workload.

  2. Open the Developer PowerShell for VS 2022.

  3. Navigate to some new empty directory, e.g.:

     > ni -Type Directory crowtest
     > cd crowtest
  4. Issue the following commands:

     > git clone https://github.com/microsoft/vcpkg.git
     > .\vcpkg\bootstrap-vcpkg.bat -disableMetrics
     > .\vcpkg\vcpkg.exe install crow 
  5. This should automatically pull in Crow and its dependencies, and build it all for you.

  6. Create CMakeLists.txt in this directory (ni CMakeLists.txt) with the following content:

     cmake_minimum_required(VERSION 3.25)
     
     project(crowtest)
     
     find_package(Crow CONFIG REQUIRED)
     
     add_executable(crowtest main.cpp)
     target_link_libraries(crowtest PRIVATE Crow::Crow)
  7. Create CMakePresets.json in this directory (ni CMakePresets.json) with the following content:

     {
         "version": 3,
         "cmakeMinimumRequired": {
             "major": 3,
             "minor": 25,
             "patch": 0
         },
         "configurePresets": [
             {
                 "name": "default",
                 "generator": "Ninja",
                 "binaryDir": "${sourceDir}/build/${presetName}",
                 "cacheVariables": {
                     "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
                 },
                 "architecture": {
                     "value": "x64",
                     "strategy": "external"
                 }
             }
         ],
         "buildPresets": [
             {
                 "name": "default-build",
                 "configurePreset": "default"
             }
         ]
     }
  8. Create main.cpp in this directory (ni main.cpp) with the following content:

     #include <crow.h>
     
     auto main() -> int {
         crow::SimpleApp app{};
    
         CROW_ROUTE(app, "/")([] {
             return "Hello world";
         });
    
         app.port(18080).multithreaded().run();
     }
  9. Issue the following commands:

     > cmake.exe --preset default 
     > cmake --build --preset default-build
     > .\build\default\crowtest.exe
     (2023-03-09 13:02:05) [INFO    ] Crow/1.0 server is running at http://0.0.0.0:18080 using 16 threads
     (2023-03-09 13:02:05) [INFO    ] Call `app.loglevel(crow::LogLevel::Warning)` to hide Info level logs.
  10. Fire up a new PowerShell instance to test, and issue the following:

     > Invoke-RestMethod -Method Get -Uri http://localhost:18080
     Hello world
     (2023-03-09 13:06:01) [INFO    ] Request: 127.0.0.1:4896 000002A736A54C80 HTTP/1.1 GET /
     (2023-03-09 13:06:01) [INFO    ] Response: 000002A736A54C80 / 200 0

1

u/tjin19 Mar 10 '23

great work man.. will try if needed!