[CDRIVER-4376] Build errors on Windows when missing C99 features Created: 02/May/22  Updated: 10/Jun/22  Resolved: 17/May/22

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.21.1
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Agostino Sturaro Assignee: Kevin Albertson
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File bson_static build 1 with errors.txt     Text File bson_static build 2 ok.txt     Text File cmake build log.txt     Text File mongoc_static build 1 with errors.txt     Text File mongoc_static build 2 with errors.txt     Text File mongoc_static build 3 with errors.txt     Text File mongoc_static build 4 with errors.txt    
Issue Links:
Related
is related to CDRIVER-3593 Remove ubuntu1204 and windows-64-vs20... Closed

 Description   

Summary

There are issues building with Visual Studio 2012 and quite likely other compilers not supporting certain C99 features.

The issues caused by stdbool.h not being defined are easy to fix.
For them, I opened this PR https://github.com/mongodb/mongo-c-driver/pull/980

For other issues, I only have a partial solution.

Environment

I'm using:

  • mongo-c-driver 1.21.1 (tag)
  • Windows Server 2019 Standard, x64, latest updates
  • Visual Studio Professional 2012 Update 5
  • CMake 3.23.1

Visual Studio 2012 is not in the continuous build, but it is supported according to the doc

Building on Windows requires Windows Vista or newer and Visual Studio 2010 or newer.

How to Reproduce

Download https://github.com/mongodb/mongo-c-driver/archive/refs/tags/1.21.1.zip
Extract the contents to C:\MyTempDir
Rename C:\MyTempDir\mongo-c-driver-1.21.1 to C:\MyTempDir\mongo-c-driver

Create a new folder C:\MyTempDir\mongo-c-driver\cmake-VS2012-x64
From that folder, run this cmd

cmake -G "Visual Studio 11 2012 Win64" -LH -DBUILD_VERSION=1.21.1 -DCMAKE_CONFIGURATION_TYPES="Debug;Release" -DCMAKE_INSTALL_PREFIX=C:/MyTempDir/mongo-c-driver/cmake-VS2012-x64 -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_PREFIX_PATH=C:/MyTempDir/mongo-c-driver/cmake-VS2012-x64 -DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_BSON=ON -DENABLE_EXAMPLES=OFF -DENABLE_ICU=OFF -DENABLE_SASL=OFF -DENABLE_SNAPPY=OFF -DENABLE_SSL=OFF -DENABLE_STATIC=ON -DENABLE_TESTS=OFF -DMONGO_USE_LLD=OFF ../

This is the cmake output: cmake build log.txt

This fix is part of PR 980.

Open C:\MyTempDir\mongo-c-driver\cmake-VS2012-x64\mongo-c-driver.sln
Ensure the build mode is Debug x64.
Build the bson_static project.
This is the build output: bson_static build 1 with errors.txt

Notice several errors like the following one

2>  bcon.c
2>C:\MyTempDir\mongo-c-driver\cmake-VS2012-x64\src\libbson\src\bson\bson-config.h(34): fatal error C1017: invalid integer constant expression

This is due to a broken BSON_HAVE_STDBOOL_H macro definition.
To solve it quickly, you can
Open C:\MyTempDir\mongo-c-driver\cmake-VS2012-x64\src\libbson\src\bson\bson-config.h
Replace this line

#define BSON_HAVE_STDBOOL_H 

with this line

#define BSON_HAVE_STDBOOL_H 0

The missing 0 in the macro is caused to a defect in a cmake script.
To fix it at the source, you can
Open C:\MyTempDir\mongo-c-driver\src\libbson\CMakeLists.txt
Under this line

CHECK_INCLUDE_FILE (stdbool.h BSON_HAVE_STDBOOL_H)

add these lines

if (NOT BSON_HAVE_STDBOOL_H)
   set (BSON_HAVE_STDBOOL_H 0)
endif ()

Build the bson_static project again.
Now it builds without errors.
This is the build output: bson_static build 2 ok.txt

This fix is also part of PR 980.

Build the mongoc_static project.
This is the build output: mongoc_static build 1 with errors.txt

There are several errors. Among them, notice this one

2>  mongoc-timeout.c
2>c:\mytempdir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-timeout-private.h(23): fatal error C1083: Cannot open include file: 'stdbool.h': No such file or directory

This is due to an include <stdbool.h> with no fallback.
The bson-compat.h has a fallback for the missing stdbool.h.

To fix the issue, open C:\MyTempDir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-timeout-private.h
Replace this line

#include <stdbool.h>

with this one

#include "bson-compat.h"

By the way, a few files in C:\MyTempDir\mongo-c-driver\src\kms-message\src have the same issue and can be fixed the same way.

The following issues are not due to missing stdbool.h.
They are not fixed by PR 980.

Build the mongoc_static project again.
This is the build output: mongoc_static build 2 with errors.txt

There are several errors like the following one

1>  mongoc-aggregate.c
1>c:\mytempdir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-topology-private.h(465): error C2059: syntax error : '{'

This is due to the mc_tpld_take_ref function using an unsupported syntax.
To fix this issue
Open C:\MyTempDir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-topology-private.h
Replace these lines

{
   return (mc_shared_tpld){
      ._sptr_ = mongoc_atomic_shared_ptr_load (&tpl->_shared_descr_._sptr_)};
}

with these lines

{
   mc_shared_tpld res;
   res._sptr_ = mongoc_atomic_shared_ptr_load (&tpl->_shared_descr_._sptr_);
   return res;
}

Build the mongoc_static project again.
This is the build output: mongoc_static build 3 with errors.txt

Notice these errors

1>  mongoc-shared.c
1>C:\MyTempDir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-shared.c(81): error C2059: syntax error : '{'
1>C:\MyTempDir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-shared.c(90): error C2059: syntax error : '{'

They are due to the MONGOC_SHARED_PTR_NULL macro using an unsupported syntax.
To fix the issue
Open C:\MyTempDir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-shared-private.h
Replace these lines

#define MONGOC_SHARED_PTR_NULL \
   ((mongoc_shared_ptr){       \
      .ptr = NULL,             \
      ._aux = NULL,            \
   })

With this line

#define MONGOC_SHARED_PTR_NULL(x) mongoc_shared_ptr x; x.ptr = NULL; x._aux = NULL

Then, open C:\MyTempDir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-shared.c
Replace this line

mongoc_shared_ptr ret = MONGOC_SHARED_PTR_NULL;

with this line

MONGOC_SHARED_PTR_NULL ( ret );

Replace this line

mongoc_shared_ptr prev = MONGOC_SHARED_PTR_NULL;

with this line

MONGOC_SHARED_PTR_NULL ( prev );

Build the mongoc_static project again.
This is the build output: mongoc_static build 4 with errors.txt

The following errors remain

1>  mongoc-timeout.c
1>c:\mytempdir\mongo-c-driver\src\libbson\src\bson\bson-prelude.h(18): fatal error C1004: unexpected end-of-file found
1>  mongoc-topology.c
1>C:\MyTempDir\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-topology.c(2008): error C2059: syntax error : '{'

I don't know how to fix them.



 Comments   
Comment by Agostino Sturaro [ 19/May/22 ]

Could you please remove my email address from your message?

Comment by Githook User [ 17/May/22 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: CDRIVER-4376 note that Visual Studio 2013 is required (#998)
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/3759a66c3116fe7e8a4da8b8d59784c60333c4ef

Comment by Kevin Albertson [ 17/May/22 ]

Hello, thank you for the detailed report. The C driver stopped testing compile in Visual Studio versions older than 2013 in the 1.17.0 release. The documentation noting Visual Studio 2010 is supported is outdated and will be updated to note that 2013 is required. We do not plan to add support back Visual Studio 2010.

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