cmake - Howto consume libraries from the conan2 cache with runpath set - Stack Overflow

I am using Conan2 almost exlusively to resolve external dependencies, i.e. 3rd party libraries. In my C

I am using Conan2 almost exlusively to resolve external dependencies, i.e. 3rd party libraries. In my CMakeLists.txt files I add them via find_package.

What confuses me is that Conan2 has at least two versions of any shared library in its cache.

  • One in a subfolder called lib. This file has usually no runpath set. Occasionally it has [//lib] set.
  • Another one in a subfolder called (for e.g. build/Debug/src). This has the runpath set to its dependencies albeit to those in the lib directories if those dependencies are also in the conan cache. The build/Debug/src directory is ignored.

After building my own projects my binarie's run path's are set to where the libraries have no runpath set in the conan cache. Why is that? Can I change it?

I would even prefer if cmake would copy those libraries to my build folder. But all targets with prebuilt binaries are INTERFACE libraries as far as cmake is concerned, and cmake refuses to touch or copy any of those - which BTW is the reason why I use install(TARGETS targets... RUNTIME_DEPENDENCIES which of course requires the runpaths in the build directory to be recursively correct.

So my question is, how can I build my project and link to dependencies from conan2 with rpath set correctly?

If you say, that setting LD_LIBRARY_PATH is the only way, then how do I set it generically?

Here is some more context:

$cat conanfile.py
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout

class MyPackage(ConanFile):

    name = "mypackage"
    version = "1.0"
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeDeps", "CMakeToolchain"

    requires = [
        "libpq/15.4",
        "libpqxx/7.10.0"
    ]

    default_options = {
        "libpq/15.4:shared": True,
        "libpqxx/7.10.0:shared": True
    }
$conan install . -pr:a=debug
...
Install finished successfully
$ find ~/.conan2 -type f -name 'libpqxx*.so*' -exec readelf -d {} \; -ls | grep -E
"RUNPATH|libpqxx.*[.]so" | grep -v soname

...~/.conan2/p/b/libpq0c77b144c4553/p/lib/libpqxx-7.10.so
... Library runpath: [/home/patrick/.conan2/p/b/libpqa76b6255bbe2f/p/lib:]
...~/.conan2/p/b/libpq0c77b144c4553/b/build/Debug/src/libpqxx-7.10.so
$ ls  /home/patrick/.conan2/p/b/libpqa76b6255bbe2f/p/lib
libpq.so  libpq.so.5  libpq.so.5.15

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744399438a4572311.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信