[CDRIVER-633] Undefined RTL_RUN_ONCE and suseconds_t with mingw Created: 05/May/15  Updated: 18/Jan/17  Resolved: 18/Jan/17

Status: Closed
Project: C Driver
Component/s: Build, libbson, mingw
Affects Version/s: 1.1.4
Fix Version/s: 1.6.0

Type: Improvement Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-959 mingw build & test in Evergreen Closed
is related to CDRIVER-441 Add missing declarations for libbson ... Closed
is related to CDRIVER-663 i386, i686, and x86_64 build & test i... Closed

 Description   

Compiling libbson on Windows with mingw64:

$ make
Scanning dependencies of target bson_shared
[  1%] Building C object CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj
In file included from C:/Users/vagrant/gittmp/libbson/src/bson/bson.h:23:0,
                 from C:/Users/vagrant/gittmp/libbson/src/bson/bcon.h:24,
                 from C:/Users/vagrant/gittmp/libbson/src/bson/bcon.c:24:
C:/Users/vagrant/gittmp/libbson/src/bson/bson-compat.h:110:9: error: unknown type name 'RTL_RUN_ONCE'
 typedef RTL_RUN_ONCE INIT_ONCE;
         ^
In file included from C:/Users/vagrant/gittmp/libbson/src/bson/bson.h:34:0,
                 from C:/Users/vagrant/gittmp/libbson/src/bson/bcon.h:24,
                 from C:/Users/vagrant/gittmp/libbson/src/bson/bcon.c:24:
C:/Users/vagrant/gittmp/libbson/src/bson/bson-iter.h: In function 'bson_iter_timeval_unsafe':
C:/Users/vagrant/gittmp/libbson/src/bson/bson-iter.h:394:18: error: 'suseconds_t' undeclared (first use in this function)
    tv->tv_sec = (suseconds_t) (value / 1000);
                  ^
C:/Users/vagrant/gittmp/libbson/src/bson/bson-iter.h:394:18: note: each undeclared identifier is reported only once for each function it appears in
CMakeFiles/bson_shared.dir/build.make:54: recipe for target 'CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj' failed
make[2]: *** [CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj] Error 1



 Comments   
Comment by Githook User [ 18/Jan/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-633 fix MinGW-W64 undefined symbols

RTL_RUN_ONCE and suseconds_t were undefined when building with CMake and
MinGW-W64. We conditionally define those if build with MS Visual Studio,
but we should conditionally define them if building on MS Windows, no
matter which compiler.
Branch: master
https://github.com/mongodb/libbson/commit/d5dc180cf5c044515afba28390ef4dc78040b0ef

Comment by Virgile Devaux [ 20/Dec/16 ]

ok, tx.
I will keep an eye on that, and compile with the msbuild tools while waiting.

Comment by A. Jesse Jiryu Davis [ 16/Dec/16 ]

Thanks Virgile, if you're not a CMake expert, don't concern yourself with this. We'll fix it in the next couple months. I've moved it to the top of our backlog. We've recently added MinGW toolchains to our build farm, so we can finally test our fixes. We'll add configure checks to the CMake and Autotools build systems.

Comment by Virgile Devaux [ 15/Dec/16 ]

unfortunatly no, I'm not very experienced with cmake.
but still, I can try
First quesiton, if I use CheckCSourceCompiles to check for missing type/decl, I will have to #include the same headers that those used in the libbson code right? Got hints for the headers to include to be as close as possible to the original source code?
Then, I might be wrong but the link you gave for RTL_RUN_ONCE shows the declaration of INIT_ONCE from RTL_RUN_ONCE that is not known. It's the same code as in bson-compat.h.
The only reference I can find about RTL_RUN_ONCE is in the Ntddk.h header. I can imagine that when compiling with VS the file is included from another header somewhere?

Comment by A. Jesse Jiryu Davis [ 14/Dec/16 ]

Thanks Virgile. If you're familiar with CMake, it'd be nice to use two CMake CheckCSourceCompiles tests, one for RTL_RUN_ONCE and one suseconds_t. For each, set a CMake variable like BSON_HAS_RTL_RUN_ONCE and BSON_HAS_SUSECONDS_T. Then add those variables to bson-config.h.in, then in bson-compat.h use those variables to define RTL_RUN_ONCE and suseconds_t if necessary.

RTL_RUN_ONCE is typedef'ed here:

https://github.com/mongodb/mongo-perl-driver/commit/7f49bfbb4e2003fc3080da9d523721decf1fcb68#commitcomment-8188246

We can use that code in bson-compat.h if necessary.

We also need a test for these two symbols in libbson's Autoconf build system, you can leave that work to us if you want.

Comment by Virgile Devaux [ 14/Dec/16 ]

As far as I am concerned, for the 1.5.0 release and the git master, the problem still arises. It looks like The problem is in libbson.
So this is not fixed. If you indeed have seen someone successfully compiling it under mingw64 on windows, could you please ask him to take a look?
First I try with the release mongo-c-driver-1.5.0.tar.gz, then with the git master https://github.com/mongodb/mongo-c-driver.git.
As the problem occurs during the libbson complation, I tried to install that separatly:
************************************************************************************************************************************
************************************************************************************************************************************
$ git clone https://github.com/mongodb/libbson.git
Clonage dans 'libbson'...
remote: Counting objects: 10445, done.
remote: Compressing objects: 100% (165/165), done.
remote: Total 10445 (delta 69), reused 0 (delta 0), pack-reused 10280
Réception d'objets: 100% (10445/10445), 6.98 MiB | 1.16 MiB/s, fait.
Résolution des deltas: 100% (7229/7229), fait.
Vérification de la connectivité... fait.

$ cd libbson/
$ cd build/
$ cmake ..
– The C compiler identification is GNU 6.2.0
– The CXX compiler identification is GNU 6.2.0
CMake Warning at /usr/share/cmake-3.6.2/Modules/Platform/MSYS.cmake:15 (message):
CMake no longer defines WIN32 on MSYS!

(1) If you are just trying to build this project, ignore this warning or
quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or in
the CMake cache. If later configuration or build errors occur then this
project may have been written under the assumption that MSYS is WIN32. In
that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead.

(2) If you are developing this project, add the line

set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required

at the top of your top-level CMakeLists.txt file or set the minimum
required version of CMake to 2.8.4 or higher. Then teach your project to
build on Cygwin without WIN32.
Call Stack (most recent call first):
/usr/share/cmake-3.6.2/Modules/CMakeSystemSpecificInformation.cmake:37 (include)
CMakeLists.txt:3 (project)

– Check for working C compiler: /mingw64/bin/cc.exe
– Check for working C compiler: /mingw64/bin/cc.exe – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: /mingw64/bin/c++.exe
– Check for working CXX compiler: /mingw64/bin/c++.exe – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
Current version (from VERSION_CURRENT file): 1.5.0-dev
Previous release (from VERSION_RELEASED file): 1.4.1
– Check if the system is big endian
– Searching 16 bit integer
– Looking for sys/types.h
– Looking for sys/types.h - found
– Looking for stdint.h
– Looking for stdint.h - found
– Looking for stddef.h
– Looking for stddef.h - found
– Check size of unsigned short
– Check size of unsigned short - done
– Using unsigned short
– Check if the system is big endian - little endian
– Looking for snprintf
– Looking for snprintf - found
– Looking for _set_output_format
– Looking for _set_output_format - found
– Looking for reallocf
– Looking for reallocf - not found
– Performing Test BSON_HAVE_TIMESPEC
– Performing Test BSON_HAVE_TIMESPEC - Success
– struct timespec found
– Looking for pthread.h
– Looking for pthread.h - found
– Looking for pthread_create
– Looking for pthread_create - found
– Found Threads: TRUE
– Looking for clock_gettime
– Looking for clock_gettime - found
– Looking for strnlen
– Looking for strnlen - found
– Looking for stdbool.h
– Looking for stdbool.h - found
– Looking for syscall
– Looking for syscall - not found
– Looking for strings.h
– Looking for strings.h - found
– Configuring done
– Generating done
– Build files have been written to: /c/Utilisateurs/A134883/Workspace/libbson/build

$ make
Scanning dependencies of target bson_shared
[ 1%] Building C object CMakeFiles/bson_shared.dir/src/bson/bcon.c.o
In file included from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bson-compat.h:37:0,
from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bson.h:23,
from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bcon.h:24,
from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bcon.c:24:
C:/Utilisateurs/A134883/Workspace/libbson/build/src/bson/bson-config.h:121:27: error: operator '!=' has no left operand
#if BSON_HAVE_SYSCALL_TID != 1
^~
In file included from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bson.h:23:0,
from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bcon.h:24,
from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bcon.c:24:
C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bson-compat.h:123:9: error: unknown type name 'RTL_RUN_ONCE'
typedef RTL_RUN_ONCE INIT_ONCE;
^~~~~~~~~~~~
In file included from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bson.h:35:0,
from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bcon.h:24,
from C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bcon.c:24:
C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bson-iter.h: In function 'bson_iter_timeval_unsafe':
C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bson-iter.h:402:18: error: 'suseconds_t' undeclared (first use in this function)
tv->tv_sec = (suseconds_t) (value / 1000);
^~~~~~~~~~~
C:/Utilisateurs/A134883/Workspace/libbson/src/bson/bson-iter.h:402:18: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [CMakeFiles/bson_shared.dir/build.make:63: CMakeFiles/bson_shared.dir/src/bson/bcon.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:143: CMakeFiles/bson_shared.dir/all] Error 2
make: *** [Makefile:161: all] Error 2
************************************************************************************************************************************
************************************************************************************************************************************
This is the same error when trying to compile the mongo-c-driver bundled version.
If you can give me a hint to start, I'm ready to work to make things going forward.

If you need any information, from my configuration, running tests, anything, just drop a comment.
tx

Comment by Hannes Magnusson [ 18/Oct/16 ]

I've seen other successfully compiling under mingw64 on Windows, so this might be fixed already.

Marking this as improvement as we don't have a mingw64 builder in evergreen to be able to properly support it

Comment by A. Jesse Jiryu Davis [ 05/May/15 ]

Caused by a commit to fix CDRIVER-441.

Comment by A. Jesse Jiryu Davis [ 05/May/15 ]

To make a repro environment on a Mac, install VirtualBox and install Windows 8.1 from an ISO:

http://download.microsoft.com/download/B/9/9/B999286E-0A47-406D-8B3D-5B5AD7373A4A/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_ENTERPRISE_EVAL_EN-US-IRM_CENA_X64FREE_EN-US_DV5.ISO

Install msys2, the 64-bit version "msys2-x86_64-20150202.exe":

http://msys2.github.io/

Then start C:\msys64\mingw64_shell.bat (irritatingly, msys2_shell.bat is just a distractor, run mingw64_shell.bat to get an actual build environment). In the window mingw64_shell.bat opens:

$ git clone https://github.com/mongodb/libbson.git
$ cd libbson
$  cmake -G "MSYS Makefiles"
... ./configure-type output ...
$ make

This produces the error output above.

Generated at Wed Feb 07 21:10:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.