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

mingw compilation fails on Ubuntu 18.04 (Bionic) #5460

Closed
adamretter opened this issue Jun 15, 2019 · 4 comments
Closed

mingw compilation fails on Ubuntu 18.04 (Bionic) #5460

adamretter opened this issue Jun 15, 2019 · 4 comments
Labels
bug Confirmed RocksDB bugs

Comments

@adamretter
Copy link
Collaborator

Compiling RocksDB on Ubuntu 18.04 (Bionic) with mingw fails.

The steps I took:

$ sudo apt-get install mingw-w64
$ sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
$ git clone https://github.com/facebook/rocksdb.git
$ cd rocksdb
$ mkdir build && cd build
$ cmake .. -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows
$ make rocksdb

The error:

[ 29%] Building CXX object CMakeFiles/rocksdb.dir/file/filename.cc.obj
[ 33%] Building CXX object CMakeFiles/rocksdb.dir/file/sst_file_manager_impl.cc.obj
[ 33%] Building CXX object CMakeFiles/rocksdb.dir/logging/auto_roll_logger.cc.obj
[ 33%] Building CXX object CMakeFiles/rocksdb.dir/logging/event_logger.cc.obj
[ 33%] Building CXX object CMakeFiles/rocksdb.dir/logging/log_buffer.cc.obj
/home/aretter/code/rocksdb/logging/log_buffer.cc: In member function ‘void rocksdb::LogBuffer::FlushBufferToLog()’:
/home/aretter/code/rocksdb/logging/log_buffer.cc:63:9: error: ‘localtime_r’ was not declared in this scope
     if (localtime_r(&seconds, &t) != nullptr) {
         ^~~~~~~~~~~
/home/aretter/code/rocksdb/logging/log_buffer.cc:63:9: note: suggested alternative: ‘localtime_s’
     if (localtime_r(&seconds, &t) != nullptr) {
         ^~~~~~~~~~~
         localtime_s
CMakeFiles/rocksdb.dir/build.make:1071: recipe for target 'CMakeFiles/rocksdb.dir/logging/log_buffer.cc.obj' failed
make[3]: *** [CMakeFiles/rocksdb.dir/logging/log_buffer.cc.obj] Error 1
CMakeFiles/Makefile2:3220: recipe for target 'CMakeFiles/rocksdb.dir/all' failed
make[2]: *** [CMakeFiles/rocksdb.dir/all] Error 2
CMakeFiles/Makefile2:3232: recipe for target 'CMakeFiles/rocksdb.dir/rule' failed
make[1]: *** [CMakeFiles/rocksdb.dir/rule] Error 2
Makefile:1156: recipe for target 'rocksdb' failed
make: *** [rocksdb] Error 2

@tamird Any ideas about how to fix this? I tried modifying port/sys_time.h to be like:

#if defined(OS_WIN) && (defined(_MSC_VER) || defined(__MINGW32__))

But that just leads to problems elsewhere in the compilation related to localtime_r.

This is the last issue I need to solve to enable us to update Travis CI to Xenial (#4789)

@adamretter adamretter added the bug Confirmed RocksDB bugs label Jun 15, 2019
@tamird
Copy link
Contributor

tamird commented Jun 15, 2019

Xenial has a newer version of mingw-w64 which is more standards compliant. Per the man page of localtime_r:

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
asctime_r(), ctime_r(), gmtime_r(), localtime_r():
_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE

Here's time.h in trusty (v3.1.0): https://github.com/mirror/mingw-w64/blob/v3.1.0/mingw-w64-headers/crt/time.h

Here's time.h in xenial (v5.0.1): https://github.com/mirror/mingw-w64/blob/v5.0.1/mingw-w64-headers/crt/time.h

So I think you need to add #define _POSIX_C_SOURCE 1 here: https://github.com/facebook/rocksdb/blob/master/port/sys_time.h#L42.

@adamretter
Copy link
Collaborator Author

@tamird thanks for the suggestion, unfortunately it doesn't seem to help.

@tamird
Copy link
Contributor

tamird commented Jun 16, 2019

I was able to reproduce. Here's what fixed it:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 006f679..eda1281 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -183,6 +183,7 @@ else()
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-strict-aliasing")
   if(MINGW)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format")
+    add_definitions(-D_POSIX_C_SOURCE=1)
   endif()
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")

My guess is that #define in port/sys_time.h is too late. Hope this helps!

@adamretter
Copy link
Collaborator Author

@tamird That fixes the issue. Awesome! - thank you very much :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed RocksDB bugs
Projects
None yet
Development

No branches or pull requests

2 participants