Skip to content

CDRIVER-4776 add thread library to pkg-config Libs #1477

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 3 commits into from
Nov 29, 2023

Conversation

kevinAlbs
Copy link
Collaborator

Summary

Add thread library to pkg-config Libs

Background & Motivation

Attempting to compile and link in separate steps with static libbson results in a linker error related to pthread with gcc 7.5.0:

# Tell pkg-config where to find .pc files:
export PKG_CONFIG_PATH=$(pwd)/.install-baseline/lib/pkgconfig
# Compile:
gcc -c ./src/libbson/examples/hello_bson.c -o hello_bson.o $(pkg-config --cflags libbson-static-1.0)
# Link:
gcc -o hello_bson hello_bson.o $(pkg-config --libs libbson-static-1.0)

Results in an error at the Link step:

/usr/bin/ld: /home/ubuntu/code/tasks/mongo-c-driver-C4776/.install/lib/libbson-static-1.0.a(common-b64.c.o): undefined reference to symbol 'pthread_once@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

man gcc notes for -pthread:

should be used consistently for both compilation and linking.

After applying these changes, the Libs section of the installed libbson-static-1.0.pc includes -pthread. The reproducing steps pass.

@kevinAlbs kevinAlbs marked this pull request as ready for review November 21, 2023 16:14
Co-authored-by: vector-of-bool <[email protected]>
@kevinAlbs kevinAlbs merged commit 9e6a816 into mongodb:master Nov 29, 2023
kevinAlbs added a commit that referenced this pull request Nov 29, 2023
* remove unused `gx_linkopts`

* add thread library to pkg-config libs

Co-authored-by: vector-of-bool <[email protected]>
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.

2 participants