Libmongoc and libbson build issues

I am facing two issues:

  1. I have followed installation instructions as mentioned in the article (64-bit binaries) Installing the MongoDB C Driver (libmongoc) and BSON library (libbson) — libmongoc 1.23.4
    I have got the following error:
    mongoc-static-1.0.lib(mongoc-compression.obj) : error LNK2019: unresolved external symbol compress2 referenced in function mongoc_compress
    I could not resolve this issue.
  2. How to build a 32-bit library? I have followed this thread Libmongoc and libbson driver Win32 Visual Studio compilation and unfortunately its throwing the following error
    CMake Error: Error: generator platform: Win32
    Does not match the platform used previously:
    Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

Any help on these issues please.

Hi @Raja_S1

  1. Are you getting this error while building the driver OR while executing your program? From the error message, it seems like the compression may be enabled and using ZLIB - mongo-c-driver/mongoc-compression.c at master · mongodb/mongo-c-driver · GitHub

The driver must be built with zlib and/or snappy and/or zstd support to enable compression support.
You may also look at this article for installing C driver on Windows using Visual Studio - Getting Started with MongoDB and C++ | MongoDB

  1. Seems like there’s a conflict with the Cmake cache. You can repeat the procedure to build in a new folder and this error should go away.
  1. Issue while building the driver. Please let me know all dependencies that needs to be mentioned during the CMake build.
  2. Thanks, its working fine now.

As of now I am moving forward with approach 2 as above i.e., 32-bit binaries.
I have linked the binaries and include file in my C++ project. It is throwing the following error

Error C2371 ‘ssize_t’: redefinition; different basic types PipeImage C:\Program Files (x86)\mongo-c-driver\include\libbson-1.0\bson\bson-compat.h 109

Please help me how to resolve this issue.
By the way I have tried including sys/types.h and couldn’t resolve it.

Can you share the code/screenshot where this error is occurring? From the error message it seems like something is being called before it is defined/declared.


Here is the code snippet, I just trying to init the Mongo instance.

Binaries location

Project settings in VS2019

Include directories

By the way I have tried C:\Program Files(x86)\mongo-c-driver as well.

For reference, It would be helpful if you could post screenshot of the entire Visual Studio window (with code and error).

Can you do a quick check for me - try to compile and run this c program (replace your code with this):

#include <mongoc/mongoc.h>

int main (int argc, char **argv)
	mongoc_client_t *client = NULL;
	bson_error_t error = {0};
	mongoc_database_t *database = NULL;
	bson_t *command = NULL, reply;

	// Initialize the MongoDB C Driver.
	mongoc_init ();

	// Replace the <connection string> with your MongoDB deployment's connection string.
	client = mongoc_client_new("<connection string>");

	// Get a handle on the "admin" database.
	database = mongoc_client_get_database (client, "admin");
	// Ping the database.
	command = BCON_NEW("ping", BCON_INT32(1));
	if (mongoc_database_command_simple(database, command, NULL, &reply, &error))
		printf("Pinged your deployment. You successfully connected to MongoDB!\n");
		// Error condition.
		printf("Error: %s\n", error.message);
		return 0;

	// Perform Cleanup.
	bson_destroy (&reply);
	bson_destroy (command);
	mongoc_database_destroy (database);
	mongoc_client_destroy (client);
	mongoc_cleanup ();

	return 0;

It is taken from the docs page -

Thanks, this example is working fine.
My project is referencing many third party libraries and never had this problem before. I’m seeing this error only after adding/referencing libbson or libmongoc.
Third party libraries = boost 1.83, python, hd5, zlib etc.

Can you please share the version of Visual Studio and compiler that you are using?

Its VS2019 and Win32 config.

I suspect there maybe a conflict with the ssize_t definition by any of the other third parties/libraries that you are using. Could you cross check for ssize_t definition in the libraries that you are using?

If I include mongo headers in another source cpp file then the issue has been resolved. Very strange!
Atleast it solved my problem. Thank you for all the help.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.