conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.14k stars 970 forks source link

[question] Managing rpaths #13012

Open jjcasmar opened 1 year ago

jjcasmar commented 1 year ago

What is your question?

I have a CMake project which uses several in-house libraries which are managed by conan. Theses libraries have also some dependencies.

The compilation and link phase are fine, but when I try to run my executables, the executable can't find some of the libraries.

I have been debugging this and it appears to be an issue with the dependency of the dependencies. That make sense because the dependencies are packaged with conan using

cmake = CMake(self)
cmake.install()

which removes the rpath, so my executable have the rpath set and can find the dependencies, but the dependencies doesn't have rpath and can't find their own dependencies.

However, I have been doing some testing with spdlog, which uses fmt as a transitive dependency, and in that case things seems to work fine.

Is this something expected? What are the best practices regarding this?

Have you read the CONTRIBUTING guide?

jjcasmar commented 1 year ago

So Ive manage to understand better this issue and why spdlog case working. Apparently, spdlog uses fmt on the interface, so at the end of the day, fmt is being linked to the executable, that is why the executable can find fmt.

I have done a small cmake example, without conan, where I have a lib which links to TBB and an aplication which links to the lib. In that case, when I install the app and the lib, the rpath of both the lib and the app are removed (which is expected), and now the app can't find the lib (I should set $ORIGIN/../lib in my case to the rpath) and the lib can't find TBB.

I understand the need to remove the rpaths to make a relocatable package so that it doesn't point to absolute paths, but, while developing several project, its a waste of space to copy the libraries using the imports.

In conan, would it make sense to set the rpaths of the packages to their dependencies in the cache, and only remove the rpath when we copy those libraries (using imports) into some other place? That way during development the libraries can find their dependencies in the cache, and when creating a relocatable package using imports, the rpaths are removed.

jjcasmar commented 1 year ago

I see why the packages in the cache can't have an absolute path as rpath, as that packages might be download from a repo, and you dont want absolutes paths in that case.

Also, relative paths, pointing directly from a library in the cache to another package in the cache doesn't work, as you might be overriding the used dependency.

But maybe, there is an alternative. When doing conan install, we know, for each library, which are its dependencies, and where they are located. Would it be possible to set the rpath of the libraries in the cache to their dependencies when doing conan install?