ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.48k stars 891 forks source link

Cannot compile Crow on Windows #179

Open philave opened 8 years ago

philave commented 8 years ago

I’m trying just to build sample from Wiki:

#include "crow_all.h"

int main()
{
    crow::SimpleApp app;

    CROW_ROUTE(app, "/")
        ([]{
        return "Hello, world!";
    });

    app
        .port(8080)
        .run();
}

First method – VS 2013 (VC++ version: 18.00.21005.1 for x86)

I get the following compilation error:

1>------ Build started: Project: CrowTest, Configuration: Debug Win32 ------
1>  helloworld.cpp
1>c:\temp\crow\crowtest\crowtest\crow_all.h(7924): fatal error C1001: An internal error has occurred in the compiler.
1>  (compiler file 'msc1.cpp', line 1325)

Ok may be VC++ compiler is incompatible with some C++ features used in the project. Let’s try GCC environment.

Second method MinGW-w64 (version: 6.2.0 platform: x86_64-w64-mingw32)

Compilation error:

In file included from helloworld.cpp:1:0:
crow_all.h: In static member function 'static std::__cxx11::string crow::logger::timestamp()':
crow_all.h:5458:36: **error: 'gmtime_r' was not declared in this scope**
                 gmtime_r(&t, &my_tm);
                                    ^
In file included from helloworld.cpp:1:0:
crow_all.h: In lambda function:
crow_all.h:9212:62: error: there are no arguments to 'gmtime_r' that depend on a template parameter, so a declaration of 'gmtime_r' must be available [-fpermissive]
                                 gmtime_r(&last_time_t, &my_tm);
                                                              ^
crow_all.h:9212:62: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
crow_all.h: In member function 'void crow::Server<Handler, Adaptor, Middlewares>::run()':
crow_all.h:9276:22: **error: 'std::this_thread' has not been declared**
                 std::this_thread::yield();
                      ^~~~~~~~~~~
crow_all.h:9280:13: error: 'thread' is not a member of 'std'
             std::thread([this]{
             ^~~
crow_all.h:9280:13: note: suggested alternative:
In file included from C:\Boost\include\boost-1_62/boost/asio/detail/win_iocp_io_service.hpp:29:0,
                 from C:\Boost\include\boost-1_62/boost/asio/impl/io_service.hpp:69,
                 from C:\Boost\include\boost-1_62/boost/asio/io_service.hpp:767,
                 from C:\Boost\include\boost-1_62/boost/asio/basic_io_object.hpp:19,
                 from C:\Boost\include\boost-1_62/boost/asio/basic_socket.hpp:20,
                 from C:\Boost\include\boost-1_62/boost/asio/basic_datagram_socket.hpp:20,
                 from C:\Boost\include\boost-1_62/boost/asio.hpp:21,
                 from crow_all.h:3267,
                 from helloworld.cpp:1:
C:\Boost\include\boost-1_62/boost/asio/detail/thread.hpp:46:20: note:   'boost::asio::detail::thread'
 typedef win_thread thread;
                    ^~~~~~
In file included from helloworld.cpp:1:0:
crow_all.h: In member function 'crow::Crow<Middlewares>::self_t& crow::Crow<Middlewares>::multithreaded()':
crow_all.h:9443:37: error: 'std::thread' has not been declared
             return concurrency(std::thread::hardware_concurrency());
                                     ^~~~~~
…

First error occurs because gmtime_s/gmtime_r functions are not defined in c/c++ standard headers. This problem can be solved by replacing the function with gmtime wrapper.

I don’t understand why the std::this_thread error occurred .

Has anyone managed to build the project on Windows? How?

gggin commented 8 years ago

please use vs2015 crow use multi c++11 grammars!

philave commented 8 years ago

Yes gggin you are right. Finally, I succeeded to build crow sample only with VS2015 and Boost 1.58

Even the latest previous version of VS (2013 Update 5) won’t compile the sample code above. With VS2013 problem occurs not in crow_all.h itself, but in Boost headers. Actually, VS2013 can build crow with older versions of Boost (e.g. Boost 1.52).

PS Maybe it would be better to mention VS2015 requirement in project Wiki

984958198 commented 7 years ago

JetBrains CLion 2017.1.3 + MinGW how build the project?

Here is the compile error

"E:\CLion 2017.1.3\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\sa\Desktop\crow-master
-- Not Found Tcmalloc: Tcmalloc_LIBRARY-NOTFOUND
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing:  OPENSSL_INCLUDE_DIR) 
CMake Warning at E:/CLion 2017.1.3/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:761 (message):
  Imported targets not available for Boost version
Call Stack (most recent call first):
  E:/CLion 2017.1.3/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:865 (_Boost_COMPONENT_DEPENDENCIES)
  E:/CLion 2017.1.3/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1454 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:22 (find_package)

CMake Warning at E:/CLion 2017.1.3/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:761 (message):
  Imported targets not available for Boost version
Call Stack (most recent call first):
  E:/CLion 2017.1.3/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:865 (_Boost_COMPONENT_DEPENDENCIES)
  E:/CLion 2017.1.3/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1454 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:22 (find_package)

CMake Error at E:/CLion 2017.1.3/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1812 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  CMakeLists.txt:22 (find_package)

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_INCLUDE_DIR (ADVANCED)
   used as include directory in directory C:/Users/sa/Desktop/crow-master
   used as include directory in directory C:/Users/sa/Desktop/crow-master
   used as include directory in directory C:/Users/sa/Desktop/crow-master
   used as include directory in directory C:/Users/sa/Desktop/crow-master
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/examples
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests/template
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests/template
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests/template
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests/template
   used as include directory in directory C:/Users/sa/Desktop/crow-master/tests/template

-- Configuring incomplete, errors occurred!
See also "C:/Users/sa/Desktop/crow-master/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "C:/Users/sa/Desktop/crow-master/cmake-build-debug/CMakeFiles/CMakeError.log".
sfxworks commented 6 years ago

I think I am having the same issue using Dev C++ 5.11 and boost 1.68.0...

10  0   D:\GitHub\crow\include\crow.h   In file included from D:\GitHub\crow\include/crow.h
1       D:\GitHub\C++Test\test.cpp                   from D:\GitHub\C++Test\test.cpp
D:\GitHub\crow\include\crow\logging.h   In static member function 'static std::string crow::logger::timestamp()':
55  36  D:\GitHub\crow\include\crow\logging.h   [Error] 'gmtime_s' was not declared in this scope
22  0   D:\GitHub\crow\include\crow.h   In file included from D:\GitHub\crow\include/crow.h
1       D:\GitHub\C++Test\test.cpp                   from D:\GitHub\C++Test\test.cpp
D:\GitHub\crow\include\crow\http_server.h   In lambda function:
86  62  D:\GitHub\crow\include\crow\http_server.h   [Error] there are no arguments to 'gmtime_s' that depend on a template parameter, so a declaration of 'gmtime_s' must be available [-fpermissive]
86  62  D:\GitHub\crow\include\crow\http_server.h   [Note] (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
D:\GitHub\crow\include\crow\http_server.h   In instantiation of 'crow::Server<Handler, Adaptor, Middlewares>::run()::<lambda()>::<lambda()> [with Handler = crow::Crow<>; Adaptor = crow::SocketAdaptor; Middlewares = {}]':
90  33  D:\GitHub\crow\include\crow\http_server.h   required from 'struct crow::Server<Handler, Adaptor, Middlewares>::run()::<lambda()> [with Handler = crow::Crow<>; Adaptor = crow::SocketAdaptor; Middlewares = {}]::<lambda()>'
93  29  D:\GitHub\crow\include\crow\http_server.h   required from 'crow::Server<Handler, Adaptor, Middlewares>::run()::<lambda()> [with Handler = crow::Crow<>; Adaptor = crow::SocketAdaptor; Middlewares = {}]'
74  67  D:\GitHub\crow\include\crow\http_server.h   required from 'struct crow::Server<Handler, Adaptor, Middlewares>::run() [with Handler = crow::Crow<>; Adaptor = crow::SocketAdaptor; Middlewares = {}]::<lambda()>'
138 26  D:\GitHub\crow\include\crow\http_server.h   required from 'void crow::Server<Handler, Adaptor, Middlewares>::run() [with Handler = crow::Crow<>; Adaptor = crow::SocketAdaptor; Middlewares = {}]'
123 17  D:\GitHub\crow\include\crow\app.h   required from 'void crow::Crow<Middlewares>::run() [with Middlewares = {}]'
11  41  D:\GitHub\C++Test\test.cpp  required from here
86  62  D:\GitHub\crow\include\crow\http_server.h   [Error] 'gmtime_s' was not declared in this scope
2225        D:\Programs\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\functional confused by earlier errors, bailing out