[CDRIVER-3431] Libraries linked with libmongoc overlinked if found via cmake Created: 17/Nov/19 Updated: 28/Oct/23 Resolved: 19/Nov/19 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | cmake |
| Affects Version/s: | 1.15.2 |
| Fix Version/s: | 1.16.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Ryan Schmidt | Assignee: | Roberto Sanchez |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
macOS |
||
| Attachments: |
|
| Description |
|
On macOS 10.13.6, I have mongo-c-driver 1.15.2 installed with MacPorts, and then I built mongo-cxx-driver 3.4.0 and noticed that the library it installed is overlinked:
Those references to libsasl2, libresolv, libsnappy, libicuuc, and the Security and CoreFoundation frameworks should not be there because libmongocxx does not itself use them. Only its dependency libmongoc uses them. I discovered that the reason for this is that mongo-cxx-driver finds out how to link with libmongoc by checking the file libmongoc-1.0-config.cmake. This file erroneously lists all of its dependencies; it should not since that's not needed for dynamic linking. (Compare with libmongoc-static-1.0-config.cmake which does and should list all of those dependencies, since it's needed for static linking.) The problem would not have arisen if mongo-cxx-driver had used pkg-config instead of cmake to find mongo-c-driver, because mongo-c-driver's libmongoc-1.0.pc already correctly does not list those libraries in its Libs line:
and libmongoc-static-1.0.pc also already correctly does list those libraries:
I fixed it by removing the lines from libmongoc-1.0-config.cmake that add the libraries, as in the attached patch. After rebuilding mongo-cxx-driver with that, it's now linked like this:
Much better. The relevant file has already been removed from your git master due to |
| Comments |
| Comment by Roberto Sanchez [ 19/Nov/19 ] | ||||||||
|
The old CMake scripts were written by hand for historical reasons. As part of
I also confirmed by inspecting the verbose build output of the C++ driver that we no longer pass superfluous library linkages out of the C driver. Note that in |