Skip to content

Fix build for FreeBSD #1243

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

Merged
merged 7 commits into from
Apr 27, 2023
Merged

Fix build for FreeBSD #1243

merged 7 commits into from
Apr 27, 2023

Conversation

kkloberdanz
Copy link
Contributor

@kkloberdanz kkloberdanz commented Apr 21, 2023

CDRIVER-4465

  • Some standard library features need __BSD_VISIBLE set to 1 to be enabled on FreeBSD
  • Cmake does not properly detect res_search on FreeBSD. Since res_search has existed since 4.3 BSD (which is the predecessor of FreeBSD), it is safe to assume that this function will exist in libc on any version of FreeBSD.

@kkloberdanz kkloberdanz changed the title builds on FreeBSD Fix build for FreeBSD Apr 21, 2023
Some standard library features need __BSD_VISIBLE set to 1 to be enabled on FreeBSD
@kkloberdanz
Copy link
Contributor Author

kkloberdanz commented Apr 24, 2023

You can use the following code to test that connecting via SRV works. One might want to connect to an instance on Atlas since the server does not support FreeBSD at this time.

#include <mongoc/mongoc.h>

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

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

  client = mongoc_client_new("<INSERT_YOUR_CONNECTION_STRING_HERE>");

  // Set the version of the Stable API on the client.
  api = mongoc_server_api_new (MONGOC_SERVER_API_V1);
  if (!mongoc_client_set_server_api (client, api, &error))
  {
    // Error condition.
    printf("Error: %s\n", error.message);
    return 0;
  }

  // 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");
  }
  else
  {
    // 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;
}

Running:

$ uname
FreeBSD
$ cc test-srv.c -I ~/install/cdriver/include/libmongoc-1.0 -I ~/install/cdriver/include/libbson-1.0 -L ~/install/cdriver/lib/ -lbson-1.0 -lmongoc-1.0 && LD_LIBRARY_PATH=~/install/cdriver/lib ./a.out
Pinged your deployment. You successfully connected to MongoDB!

@kkloberdanz kkloberdanz marked this pull request as ready for review April 24, 2023 20:54
@kkloberdanz kkloberdanz requested a review from kevinAlbs April 25, 2023 20:48
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one comment addressed.

Co-authored-by: Kevin Albertson <[email protected]>
Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kkloberdanz kkloberdanz merged commit 4a0e816 into mongodb:master Apr 27, 2023
@kkloberdanz kkloberdanz deleted the CDRIVER-4465 branch April 27, 2023 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants