[CDRIVER-2263] Undefined symbol "pthread_once" compiling tests Created: 01/Sep/17  Updated: 27/Oct/23  Resolved: 01/Sep/17

Status: Closed
Project: C Driver
Component/s: tests
Affects Version/s: 1.7.0
Fix Version/s: 1.8.0

Type: Bug Priority: Major - P3
Reporter: Derick Rethans Assignee: Hannes Magnusson
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-672 Delete supplemental tests Closed

 Description   

The compilation fails with:

  CCLD     libmongoc-1.0.la
  CCLD     libmongoc-priv.la
  CCLD     mongoc-stat
ar: `u' modifier ignored since `D' is the default (see `U')
  CCLD     test-load
  CCLD     test-secondary
  CCLD     test-replica-set
  CCLD     test-sharded-cluster
/usr/bin/ld: tests/test_replica_set-ha-test.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
Makefile:2971: recipe for target 'test-replica-set' failed
make[1]: *** [test-replica-set] Error 1
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: ./.libs/libmongoc-priv.a(libmongoc_priv_la-mongoc-init.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
/usr/bin/ld: ./.libs/libmongoc-priv.a(libmongoc_priv_la-mongoc-init.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
Makefile:2989: recipe for target 'test-secondary' failed
make[1]: *** [test-secondary] Error 1
Makefile:2961: recipe for target 'test-load' failed
make[1]: *** [test-load] Error 1
/usr/bin/ld: tests/test_sharded_cluster-ha-test.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
Makefile:2999: recipe for target 'test-sharded-cluster' failed
make[1]: *** [test-sharded-cluster] Error 1
make[1]: Leaving directory '/home/derick/dev/mongodb-mongo-c-driver'
Makefile:5977: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
[GIT: (tags/1.7.0^0)]



 Comments   
Comment by Hannes Magnusson [ 01/Sep/17 ]

heh. My bad. I also failed at scrolling down to see the rest of the errors

Anyway, since r1.8 works, and this doesn't affect the bundled version for php I think we should close this as gone away in 1.8.

mongoc and the tests was built and linked correctly, it was just the never-used-extra tests that failed linking
Please do re-open if you disagree.

Comment by Derick Rethans [ 01/Sep/17 ]

And it wasn't just one, it was all "four". It's just that it stops after the first one fails with "make -j1"

Comment by Derick Rethans [ 01/Sep/17 ]

I'm on Debian Linux, with GCC

gcc (Debian 6.4.0-3) 6.4.0 20170805

.

Disabling the tests helps, or compiling from master, or from r1.8.

Comment by Hannes Magnusson [ 01/Sep/17 ]

You can disable tests with

./autogen.sh --disable-tests

Since you are using ./autogen.sh it seems you are using git, in which case, please try master, or the r1.8 branch.


This is pretty weird though, as the test files shared the library link list: https://github.com/mongodb/mongo-c-driver/blob/r1.7/tests/Makefile.am
so if one fails, all should fail at least.

But I think this is a won't fix since this is already removed in r1.8, see CDRIVER-672

Comment by A. Jesse Jiryu Davis [ 01/Sep/17 ]

I haven't seen this myself. Also, the ha_test executable is being removed in 1.8.0 (CDRIVER-672). What's your OS and compiler?

Comment by Derick Rethans [ 01/Sep/17 ]

It seems to be that -pthread is missing from the linker lines. If I add that myself, it compiles and links:

/bin/bash ./libtool  --tag=CC   --mode=link gcc  -Wno-format-nonliteral  -Wno-deprecated-declarations -DMONGOC_COMPILATION -I/usr/include/libbson-1.0     -I./src/mongoc -I./src/mongoc -DMONGOC_ENABLE_SHM_COUNTERS -DBINARY_DIR="\"./tests/binary\"" -DJSON_DIR="\"./tests/json\"" -DCERT_TEST_DIR="\"./tests/x509gen\"" -DOS_RELEASE_FILE_DIR="\"./tests/release_files\"" -O2   -o test-load tests/test_load-test-load.o tests/test_load-mongoc-tests.o  libmongoc-priv.la  -lrt -lsasl2  -lz -lssl -lcrypto -lbson-1.0 -pthread

./autogen.sh

outputs this related to pthread:

checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no
checking for PTHREAD_PRIO_INHERIT... yes
checking whether the linker accepts -Wl,-Bsymbolic... yes

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