You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If building the application with cmake, the [Default RPATH settings](https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#default-rpath-settings) include the full RPATH to all used libraries in the build tree. However, when installing, cmake will clear the RPATH of these targets so they are installed with an empty RPATH. This may result in a `Library not loaded` error after install.
215
+
216
+
Example:
217
+
```sh
218
+
# Build application `app` using the C++ driver from a non-standard install.
219
+
cmake \
220
+
-DCMAKE_PREFIX_PATH=$HOME/mongo-cxx-driver \
221
+
-DCMAKE_INSTALL_PREFIX=$HOME/app \
222
+
-DCMAKE_CXX_STANDARD=11 \
223
+
-Bcmake-build -S.
224
+
cmake --build cmake-build --target app.out
225
+
# Running app.out from build tree includes rpath to C++ driver.
226
+
./cmake-build ./cmake-build/app.out
227
+
# Prints: "successfully connected with C++ driver"
228
+
229
+
cmake --build cmake-build --target install
230
+
# Running app.out from install tree does not include rpath to C++ driver.
231
+
$HOME/app/bin/app.out
232
+
# Prints "Library not loaded" error.
233
+
```
234
+
235
+
Consider setting `-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE` so the rpath for the executable is kept in the install target.
236
+
```sh
237
+
# Build application `app` using the C++ driver from a non-standard install.
238
+
# Use CMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE to keep rpath entry on installed app.
239
+
cmake \
240
+
-DCMAKE_PREFIX_PATH=$HOME/mongo-cxx-driver \
241
+
-DCMAKE_INSTALL_PREFIX=$HOME/app \
242
+
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE \
243
+
-DCMAKE_CXX_STANDARD=11 \
244
+
-Bcmake-build -S.
245
+
246
+
cmake --build cmake-build --target install
247
+
$HOME/app/bin/app.out
248
+
# Prints "successfully connected with C++ driver"
249
+
```
250
+
251
+
See the cmake documentation for [RPATH handling](https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling) for more information.
252
+
253
+
### Fixing the "cannot open shared object file" error on Linux
254
+
255
+
Applications linking to a non-standard directory installation may encounter an error loading the C++ driver at runtime. Example:
256
+
257
+
```sh
258
+
# Tell pkg-config where to find C++ driver installation.
If building the application with cmake, the [Default RPATH settings](https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#default-rpath-settings) include the full RPATH to all used libraries in the build tree. However, when installing, cmake will clear the RPATH of these targets so they are installed with an empty RPATH. This may result in a `Library not loaded` error after install.
286
+
287
+
Example:
288
+
```sh
289
+
# Build application `app` using the C++ driver from a non-standard install.
290
+
cmake \
291
+
-DCMAKE_PREFIX_PATH=$HOME/mongo-cxx-driver \
292
+
-DCMAKE_INSTALL_PREFIX=$HOME/app \
293
+
-DCMAKE_CXX_STANDARD=11 \
294
+
-Bcmake-build -S.
295
+
cmake --build cmake-build --target app.out
296
+
# Running app.out from build tree includes rpath to C++ driver.
297
+
./cmake-build ./cmake-build/app.out
298
+
# Prints: "successfully connected with C++ driver"
299
+
300
+
cmake --build cmake-build --target install
301
+
# Running app.out from install tree does not include rpath to C++ driver.
302
+
$HOME/app/bin/app.out
303
+
# Prints "cannot open shared object file" error.
304
+
```
305
+
306
+
Consider setting `-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE` so the rpath for the executable is kept in the install target.
307
+
```sh
308
+
# Build application `app` using the C++ driver from a non-standard install.
309
+
# Use CMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE to keep rpath entry on installed app.
310
+
cmake \
311
+
-DCMAKE_PREFIX_PATH=$HOME/mongo-cxx-driver \
312
+
-DCMAKE_INSTALL_PREFIX=$HOME/app \
313
+
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE \
314
+
-DCMAKE_CXX_STANDARD=11 \
315
+
-Bcmake-build -S.
316
+
317
+
cmake --build cmake-build --target install
318
+
$HOME/app/bin/app.out
319
+
# Prints "successfully connected with C++ driver"
320
+
```
321
+
322
+
See the cmake documentation for [RPATH handling](https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling) for more information.
0 commit comments