[CDRIVER-606] Static library build failure on Mac OS Created: 04/Apr/15  Updated: 07/Oct/15  Resolved: 06/Apr/15

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

Type: Bug Priority: Minor - P4
Reporter: Paul Melnikow Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Version: 1.1.0 or latest master
Host OS: OS X 10.10.2
Compiler: Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)



 Description   

I'm encountering a linker error consuming a libmongoc static library I built through Xcode:
https://groups.google.com/forum/#!topic/mongodb-user/E7qkt9con3A

I was able to replicate the exact linker error outside of Xcode, using the library's own build system. The error occurs when I build just the static library, and not the dylib.

```
./autogen.sh
./configure --with-libbson=no --enable-ssl=no --enable-sasl=no --disable-shared --enable-static && make
```

The static library seems to be missing the non-extern declarations for the counter types, and the linker errors arise when building the tests:

```
CC tests/test_secondary-test-secondary.o
CC tests/test_secondary-mongoc-tests.o
CCLD test-secondary
clang: warning: argument unused during compilation: '-pthread'
Undefined symbols for architecture x86_64:
"___mongoc_counter_auth_failure", referenced from:
__mongoc_cluster_auth_node in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_auth_success", referenced from:
__mongoc_cluster_auth_node in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_clients_active", referenced from:
_mongoc_client_new in libmongoc-priv.a(libmongoc_priv_la-mongoc-client.o)
_mongoc_client_destroy in libmongoc-priv.a(libmongoc_priv_la-mongoc-client.o)
"___mongoc_counter_clients_disposed", referenced from:
_mongoc_client_destroy in libmongoc-priv.a(libmongoc_priv_la-mongoc-client.o)
"___mongoc_counter_cursors_active", referenced from:
__mongoc_cursor_new in libmongoc-priv.a(libmongoc_priv_la-mongoc-cursor.o)
__mongoc_cursor_destroy in libmongoc-priv.a(libmongoc_priv_la-mongoc-cursor.o)
__mongoc_cursor_clone in libmongoc-priv.a(libmongoc_priv_la-mongoc-cursor.o)
"___mongoc_counter_cursors_disposed", referenced from:
__mongoc_cursor_destroy in libmongoc-priv.a(libmongoc_priv_la-mongoc-cursor.o)
"___mongoc_counter_dns_failure", referenced from:
_mongoc_client_default_stream_initiator in libmongoc-priv.a(libmongoc_priv_la-mongoc-client.o)
"___mongoc_counter_dns_success", referenced from:
_mongoc_client_default_stream_initiator in libmongoc-priv.a(libmongoc_priv_la-mongoc-client.o)
"___mongoc_counter_op_egress_delete", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_egress_getmore", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_egress_insert", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_egress_killcursors", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_egress_msg", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_egress_query", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_egress_reply", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_egress_total", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_egress_update", referenced from:
__mongoc_cluster_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
__mongoc_cluster_try_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_delete", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_getmore", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_insert", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_killcursors", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_msg", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_query", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_reply", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_total", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_op_ingress_update", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_protocol_ingress_error", referenced from:
__mongoc_cluster_try_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-cluster.o)
"___mongoc_counter_streams_active", referenced from:
_mongoc_stream_buffered_new in libmongoc-priv.a(libmongoc_priv_la-mongoc-stream-buffered.o)
_mongoc_stream_buffered_destroy in libmongoc-priv.a(libmongoc_priv_la-mongoc-stream-buffered.o)
"___mongoc_counter_streams_disposed", referenced from:
_mongoc_stream_buffered_destroy in libmongoc-priv.a(libmongoc_priv_la-mongoc-stream-buffered.o)
"___mongoc_counter_streams_egress", referenced from:
_mongoc_socket_sendv in libmongoc-priv.a(libmongoc_priv_la-mongoc-socket.o)
"___mongoc_counter_streams_ingress", referenced from:
_mongoc_socket_recv in libmongoc-priv.a(libmongoc_priv_la-mongoc-socket.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```



 Comments   
Comment by Githook User [ 07/Oct/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: Merge remote-tracking branch 'upstream/master' into 1.2.0-dev

  1. By A. Jesse Jiryu Davis (7) and others
  • upstream/master:
    CDRIVER-606 Call mongoc_init () in test-secondary
    Begin next release's changelog
    Spelling.
    Include header for suppress_one_message() in test-mongoc-uri.c.
    CDRIVER-605 fix function name in collection_find_indexes page.
    Fix version no. in guide to building from release tarball.
    post release bump
    Release 1.1.4
    CDRIVER-580: fsync or j in write concern imply GLE
    Use write concern macros instead of magic numbers
    CDRIVER-560: Include private header in mongoc-client-pool.c.

Conflicts:
src/libbson
src/mongoc/mongoc-client-pool.c
src/mongoc/mongoc-uri.c
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/673d4a7aab3d8b46a676ea97b4cd46c5956f976c

Comment by Githook User [ 07/Apr/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: Merge remote-tracking branch 'upstream/master' into 1.2.0-dev

  1. By A. Jesse Jiryu Davis (7) and others
  • upstream/master:
    CDRIVER-606 Call mongoc_init () in test-secondary
    Begin next release's changelog
    Spelling.
    Include header for suppress_one_message() in test-mongoc-uri.c.
    CDRIVER-605 fix function name in collection_find_indexes page.
    Fix version no. in guide to building from release tarball.
    post release bump
    Release 1.1.4
    CDRIVER-580: fsync or j in write concern imply GLE
    Use write concern macros instead of magic numbers
    CDRIVER-560: Include private header in mongoc-client-pool.c.

Conflicts:
src/libbson
src/mongoc/mongoc-client-pool.c
src/mongoc/mongoc-uri.c
Branch: 1.2.0-dev
https://github.com/mongodb/mongo-c-driver/commit/673d4a7aab3d8b46a676ea97b4cd46c5956f976c

Comment by Githook User [ 07/Apr/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-606 Call mongoc_init () in test-secondary

Besides being a correct use of libmongoc, it also fixes building with
"./configure --disable-shared --enable-static" and clang on Mac.
Branch: 1.2.0-dev
https://github.com/mongodb/mongo-c-driver/commit/2ef028cdbc21eb2b9e47d8bb51520f73d4e584c2

Comment by Paul Melnikow [ 07/Apr/15 ]

Ah, great! Adding mongoc_init() fixes the problem I'm seeing, as does `-all_load` or `-force_load $(TARGET_BUILD_DIR)/libPods-ObjCMongoDB-mongo-c-driver.a`. Nonetheless, a bizarre error.

Thanks!

Comment by Githook User [ 06/Apr/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-606 Call mongoc_init () in test-secondary

Besides being a correct use of libmongoc, it also fixes building with
"./configure --disable-shared --enable-static" and clang on Mac.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/2ef028cdbc21eb2b9e47d8bb51520f73d4e584c2

Comment by A. Jesse Jiryu Davis [ 06/Apr/15 ]

Oh, that test file is missing the call to mongoc_init, which would trigger the inclusion of those symbols.

Comment by A. Jesse Jiryu Davis [ 06/Apr/15 ]

Only test-secondary has this failure. It has something to do with the particular source contents of test-secondary.c; the other tests build correctly and if I simply replace test-secondary.c's contents with another test's source, it builds.

It's a Mac-specific (or clang-specific) problem: With gcc on Linux, running the same ./configure line as you did in Linux builds all test files correctly.

Appending -Wl,-all_load to the gcc build line allows the build to proceed on Mac.

I can't tell what's special about test-secondary or what the proper solution is. Is adding -Wl,-all_load to the build line on Mac is justified?

Comment by A. Jesse Jiryu Davis [ 05/Apr/15 ]

Thanks for reporting, we'll take a look at this early next week.

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