[CXX-2116] Document rpath for non-standard install location Created: 04/Oct/20 Updated: 28/Oct/23 Resolved: 04/Nov/20 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | Documentation |
| Affects Version/s: | None |
| Fix Version/s: | 3.7.0, 3.7.0-beta1 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Jesse Pai | Assignee: | Roberto Sanchez |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I have been tinkering around with building a "superbuild" CMake project that downloads and builds the mongo-cxx driver for inclusion into a project. To do this, I used the ExternalProject_Add and then manually linked the libmongocxx.so shared object to the final executable/library. Here's what the CMakeLists.txt roughly looks like:
This configuration builds the hello_world application correctly, but when I go to execute the application, the following error occurs:
When running ldd on the installed libmongocxx.so, it turns out, libbsoncxx.so._noabi is not found.
One way to work around it is to set the LD_LIBRARY_PATH to the same directory as libmongocxx.so (and libbsoncxx.so). But this isn't really a good solution since, this would mean the application must have specific environment settings just to get the application to point to the local/non-standard shared object location. I have instead managed to work around this particular problem by linking the build output directory's version of libmongocxx.so. This version of libmongocxx.so links to the build directory's version of libbsoncxx.so. So instead of using the NOTE section from above, I use the following variable setting:
With this, the application works without the missing shared object error. I wanted to ask why there was such a difference between the linking of the installed directory version of libmongocxx.so and the build directory version of libmongocxx.so. Considering the install operation of the project seems to drop all the necessary shared objects into the same directory, I am not sure why the installed version of libmongocxx.so was not able to pick up libbsoncxx.so object next to it. I wanted to see if there is a way to fix this so that the mongo-cxx-driver can be a bit more portable and not need to be directly installed into the system libraries. I don't think it is good practice to directly reference the build object when the project has an install target available for it. Thanks! |
| Comments |
| Comment by Githook User [ 04/Nov/20 ] |
|
Author: {'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}Message: |
| Comment by Jesse Pai [ 03/Nov/20 ] |
|
Ah yes. I forgot about that CMAKE variable. That is certainly an option and is probably a better idea. I will try it out and see if it works for my use case. Thanks for taking a look into this! |
| Comment by Roberto Sanchez [ 03/Nov/20 ] |
|
jesse.pai@gmail.com, I have investigated this. The issue is that the build sets rpath for artifacts in the build directory and then clears rpath when they are copied to the install location. If you specify -DCMAKE_INSTALL_RPATH=<prefix>/lib (where <prefix> is the same directory you specified as your installation prefix), then the target directory where the libraries are to be installed will be used as the rpath. That should eliminate the loader error you are seeing. We are updating the installation docs to include this information. |
| Comment by Kevin Albertson [ 05/Oct/20 ] |
|
Hi jesse.pai@gmail.com, thank you for the detailed report! We will look into this soon. |