[CDRIVER-4776] Include -pthread in pkg-config Libs Created: 08/Nov/23  Updated: 29/Nov/23  Resolved: 29/Nov/23

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

Type: Bug Priority: Unknown
Reporter: Kevin Albertson Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When upgrading the C driver dependency in the C++ driver to 1.25.0, the following error occurred building an example project (example task):

[2023/11/08 12:14:47.192] Example bsoncxx/pkg-config/static failed
[2023/11/08 12:14:47.193] -DBSONCXX_STATIC -pthread -DBSON_STATIC -I/data/mci/e9fe78cca062add974871e9ff01524c3/mongoc/include/libbson-1.0 -I/data/mci/e9fe78cca062add974871e9ff01524c3/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc -I/data/mci/e9fe78cca062add974871e9ff01524c3/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi -I/data/mci/e9fe78cca062add974871e9ff01524c3/mongo-cxx-driver/build/install/include
[2023/11/08 12:14:47.193] /usr/bin/ld: /data/mci/e9fe78cca062add974871e9ff01524c3/mongoc/lib/libbson-static-1.0.a(common-b64.c.o): undefined reference to symbol 'pthread_once@@GLIBC_2.2.5'
[2023/11/08 12:14:47.193] /usr/bin/ld: //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
[2023/11/08 12:14:47.193] collect2: error: ld returned 1 exit status

Here are the contents of libbson-1.0-static.pc on C driver 1.25.0 built on Ubuntu 18.04:

# pkg-config .pc file generated by CMake 3.25.3 for libbson-1.25.0. DO NOT EDIT!
prefix=/home/ubuntu/code/tasks/mongo-cxx-driver-release-3.9.0/mongoc
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
 
Name: libbson
Description: The libbson BSON serialization library
Version: 1.25.0
 
Libs: -L${libdir} -lbson-static-1.0 -L/usr/lib/x86_64-linux-gnu -lrt
Cflags: -pthread -DBSON_STATIC -I${prefix}/include/libbson-1.0

I expect -pthread may need to be included in Libs. A similar change may be needed for libmongoc-1.0-static.pc.

The failing task compiles and links in separate commands:

$CXX $CXXFLAGS -Wall -Wextra -Werror -std="c++${CXX_STANDARD}" -c -o hello_bsoncxx.o ../../../hello_bsoncxx.cpp $(pkg-config --cflags libbsoncxx-static)
$CXX $LDFLAGS -std="c++${CXX_STANDARD}" -o hello_bsoncxx hello_bsoncxx.o $(pkg-config --libs libbsoncxx-static)

A simple workaround is to set -pthread flag in the link command. This workaround was applied in https://github.com/mongodb/mongo-cxx-driver/pull/1056.



 Comments   
Comment by Githook User [ 29/Nov/23 ]

Author:

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

Message: CDRIVER-4776 add thread library to pkg-config `Libs` (#1477)

  • remove unused `gx_linkopts`
  • add thread library to pkg-config libs

Co-authored-by: vector-of-bool <vectorofbool@gmail.com>
Branch: r1.25
https://github.com/mongodb/mongo-c-driver/commit/842f67b9f21b65ed55396516317c99278978ce63

Comment by Githook User [ 29/Nov/23 ]

Author:

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

Message: CDRIVER-4776 add thread library to pkg-config `Libs` (#1477)

  • remove unused `gx_linkopts`
  • add thread library to pkg-config libs

Co-authored-by: vector-of-bool <vectorofbool@gmail.com>
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/9e6a816b01888e7562912729bdf42843ca016f69

Comment by Githook User [ 08/Nov/23 ]

Author:

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

Message: Bump required C driver to 1.25.0 (#1056)

  • bump required C driver to 1.25.0
  • remove reference to removed EVG variant

"Ubuntu 18.04 with minimum libmongoc" was removed in PR #1049. Testing with minimum libmongoc is now the default.

  • remove step for updating docker versions

This step is listed in later in `Docker Image Build and Publish`.

Building the Docker images requires downloading the C++ release tarball. Bump after tagging.

  • remove `check_docker_file_versions`

The Docker versions are bumped after tagging the release. This check may not be expected to succeed during a release.

  • fix documented introduction of the auto C driver download

It is introduced in 3.9.0 as part of CXX-2695.

  • add `-pthread` to example project build scripts

This is a workaround until CDRIVER-4776 is resolved.
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/19a6099adc00a920e60229528b771c0c2fbc28ae

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