Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed 'localtime_*' compilation error MinGW #393

Merged
merged 1 commit into from
Jan 14, 2015
Merged

Conversation

Schebb
Copy link
Contributor

@Schebb Schebb commented Jan 6, 2015

I got the following compilation error when compiling a project including websocketpp with MinGW:

[ 95%] Building CXX object CMakeFiles/Sources/MyProject/CMakeFiles/MyProject.dir/TestClient.cpp.obj
In file included from F:/Project/MyProject/build/cmake/../../extlibs/include/websocketpp/logger/basic.hpp:49:0,
from F:/Project/MyProject/build/cmake/../../extlibs/include/websocketpp/config/core.hpp:51,
from F:/Project/MyProject/build/cmake/../../extlibs/include/websocketpp/config/asio_no_tls.hpp:31,
from F:\Project\MyProject\Sources\MyProject\WebSocketClient.hpp:8,
from F:\Project\MyProject\Sources\MyProject\TestClient.hpp:34,
from F:\Project\MyProject\Sources\MyProject\TestClient.cpp:2:
F:/Project/MyProject/build/cmake/../../extlibs/include/websocketpp/common/time.hpp: In function 'tm websocketpp::lib::localtime(const time_t&)':
F:/Project/MyProject/build/cmake/../../extlibs/include/websocketpp/common/time.hpp:44:36: error: 'localtime_s' was not declared in this scope
localtime_s(&tm_snapshot, &time);
^
compilation terminated due to -Wfatal-errors.
CMakeFiles\Sources\MyProject\CMakeFiles\MyProject.dir\build.make:57: recipe for target 'CMakeFiles/Sources/MyProject/CMakeFiles/MyProject.dir/TestClient.cpp.obj' failed
make[3]: *** [CMakeFiles/Sources/MyProject/CMakeFiles/MyProject.dir/TestClient.cpp.obj] Error 1
CMakeFiles\Makefile2:1063: recipe for target 'CMakeFiles/Sources/MyProject/CMakeFiles/MyProject.dir/all' failed
make[2]: *** [CMakeFiles/Sources/MyProject/CMakeFiles/MyProject.dir/all] Error 2
CMakeFiles\Makefile2:1075: recipe for target 'CMakeFiles/Sources/MyProject/CMakeFiles/MyProject.dir/rule' failed
make[1]: *** [CMakeFiles/Sources/MyProject/CMakeFiles/MyProject.dir/rule] Error 2

Makefile:329: recipe for target 'MyProject' failed
make: *** [MyProject] Error 2

Note

MinGW does not define neither localtime_s nor locatime_r.

Discussion here: http://stackoverflow.com/questions/18551409/localtime-r-support-on-mingw
MinGW Note here: http://sourceforge.net/p/mingw-w64/mailman/message/21523522/

@Schebb
Copy link
Contributor Author

Schebb commented Jan 6, 2015

I naively took my change from #392
but It appears my project cannot compile with this branch (develop) of websocketpp. I got an error about the header of std::mutex that is missing. (I will check this after lunching)

@Schebb
Copy link
Contributor Author

Schebb commented Jan 6, 2015

concerning my previous comment: my error about std::mutex is due to MinGW (again :s) that still haven't a standard threads implementation.

Users of MinGW can either:

(we could detect MinGW and automatically add this macro in the code or just wait the MinGW's team)

Anyway, I don't know why travis failed here.

@zaphoyd
Copy link
Owner

zaphoyd commented Jan 6, 2015

travis failed due to a finicky timer test that I should probably remove since it gets a lot of false positives.

Falling back to boost thread would be a good default here. I'll look into autodetecting that. A few things you could help me with in that regard:

  • Does MinGW have a "C++11 mode/switch" in the way that g++ does with -std=c++11? If so are you using it?
  • When used in C++11 mode, either via the switch or because its always on, what is the value of the __cplusplus define?

@Schebb
Copy link
Contributor Author

Schebb commented Jan 6, 2015

I am not an expert in MinGW, so I compiled this code for answering your question:

#include <iostream>

int main( void ) {
    auto func = [] { std::cout << "__cplusplus : " << __cplusplus << std::endl; };
    func();
    return 0;
}

and I got the following input:

C:\Users\Scheb\Desktop\testmingw>mingw32-g++ --version
mingw32-g++ (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


C:\Users\Scheb\Desktop\testmingw>mingw32-g++ -o test main.cpp
main.cpp: In function 'int main()':
main.cpp:5:7: error: 'func' does not name a type
  auto func = [] { std::cout << "__cplusplus : " << __cplusplus << std::endl; };

       ^
main.cpp:6:7: error: 'func' was not declared in this scope
  func();
       ^

C:\Users\Scheb\Desktop\testmingw>mingw32-g++ -o test main.cpp -std=c++11

C:\Users\Scheb\Desktop\testmingw>test.exe
__cplusplus : 201103

Consequently, I would answer

  1. Yes, same as g++ (as often); it is "-std=c++11"
  2. oh, I didn't know the value of __cplusplus could be useful.. Here, in C++11 mode it is '201103' (and without c++11 mode activated, it is 199711).

@zaphoyd
Copy link
Owner

zaphoyd commented Jan 6, 2015

I've pushed an update to the C++11 thread support detection code that should force the use of boost thread by default for MinGW even when it is building in C++11 mode. Can you confirm that this fixes the issue you were seeing without requiring you to include any special preprocessor defines?

@zaphoyd zaphoyd added this to the 0.5.0 milestone Jan 6, 2015
@Schebb
Copy link
Contributor Author

Schebb commented Jan 7, 2015

Confirmed; I checkout from 'develop' branch (replaced websocketpp\common\time.hpp with the changes on this pull request) and no error.

Note that in "if (defined(MINGW32) || defined(MINGW64))", checking MINGW64 is not really necessary because I think mingw64 defines also MINGW32. Thus, checking MINGW32 alone could be enough. But for me, it's more clear for an external readers that might think MINGW64 is missing.

zaphoyd added a commit that referenced this pull request Jan 14, 2015
fixed 'localtime_*' compilation error MinGW
@zaphoyd zaphoyd merged commit 1d29d48 into zaphoyd:develop Jan 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants