1

I am using Conan2 to resolve external dependencies. I add them via find_ package in my CMakeLists.txt.

My own project binaries created by cmake --build ... have their run path's set by cmake pointing to dependencies living in the conan cache. But those binaries in the conan cache have no runpath set.

Example: libcrypto.so in the conan cache will have no runpath set and load the system installed libssl.so, which has the wrong version. It will not find the correct version which is available in the conan cache.

My solution so far is to always build and install into an installation directory which I use to test or debug. This works totally fine for me but there are some limitations. CTest for example, assumes running from within the build directory, hence I cannot use that. gtest however is no problem and I prefer using its test binaries directly anyhow.

If you say, that setting LD_LIBRARY_PATH is the only way, then how do I set it generically in CMakeLists.txt or conanfile.py?

1 Answer 1

0

Conan creates scripts to set the LD_LIBRARY_PATH as needed during conan install or conan build. Example:

bash
. build/Debug/generators/conanrun.sh

After exiting the shell, the environment will be restored.

LD_LIBRARY_PATH does not need to be available during build time. The above command sets it to the correct conan cache directories, which solves the problem of running the binaries in the terminal.

vscode will use the environment in the terminal if invoked via the terminal:

code . 

Otherwise you can configure .vscode/launch.json and .vscode/tasks.json

# add this to a launch configuration:
   "preLaunchTask": "source-conan-env"

# add this to the task configuration 
   {
       "label": "source-conan-env",
       "type": "shell",
       "command": ". ${workspaceFolder}/build/debug/generators/conanrun.sh",
       "problemMatcher": []
   }

It's a bit annoying when sourcing the conan environment while forgetting to enter a shell first, as you then cannot revert the settings. Conan provides deactivate scripts for that, but they are brittle to use in my experience. . ~/.bashrc fixes that most of the cases though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.