-
Notifications
You must be signed in to change notification settings - Fork 952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] How to tell binary in one dependency where to find shared library in another one? #15155
Comments
I tried building grpc as shared library by setting the respective option in the conanfile.txt
Then I get the error:
Now the executable doesn't find a lib from the same package - which makes sense, when the environment variables are not properly set. |
Thanks for your question. I think you are seeing a limitation of the CMake-conan flow. This flow is not capable of setting the environment or enviroment variables that might be necessary to locate dependencies at runtime. There can be different approaches:
|
Hi @memsharded, and again, thanks for helping me out! So far, we are using protobuf statically, but due to some issues (more details here) when using it through shared libraries and directly, we wanted to test if using it as shared library could be beneficial. Some further questions concerning your advice:
A solution I could think of, would be to build part of grpc (the executables) with static protobuf library, while the other part (the libraries) should depend on the shared protobuf library. But that sounds like a horrible idea.
I don't think that this approach is viable for me, because it would mean that the consumers of my packages would always need to manually invoke Conan and activate the environment by themselves. I like that everything is currently integrated into CMake and people don't need to do anything. Do I understand correctly, that it's not possible to integrate running the activation script into CMake? I tried using a custom target
..but that didn't work. Probably because the scope in which the script is executed (and the environment variables set) is different from the one in which cmake runs. I found a stackoverflow answer claiming that toolchain-files are an approach to set environment variables. So I added Thanks and best regards, |
The concept can be illustrated more clearly if you are cross compiling, lets say from a Windows laptop, to an embedded Linux based target:
If you want to use libprotobuf and protoc in this context 3 things are needed:
Because when you need to run This is exactly the same scenario than when using "shared". You want your project to be linked with
It is not that straightforward, but we have some plans to try to add env-vars directly to CMake, so it is not necessary to use environment activation scripts like the ones generated now. In any case, it seems you are using the legacy enviroment, the correct ones are the ones generated with |
I changed my conanfile.txt to
And then added two profiles: host.profile
and build.profile
Then I ran
The same error as before occured. I have to admit that I don't understand the two-profiles approach at all. If you're motivated trying to explain it to me again, then I would be very grateful. If not, feel free to close this issue. I will stick to static libraries and work around the limitations. Thanks again for your efforts. |
Have you had the chance to do the tutorial? It is a bit difficult to reproduce what you are describing. If you want to use the cmake-conan integration, you need to follow https://github.com/conan-io/cmake-conan and make sure that the different profiles are passed, etc. What you do in |
Thanks for the hint concerning the conan-cmake mechanism. However, my project also contains libraries that link to protobuf and grpc. If I now build the project, the static version of protobuf is linked, but this is what I would like to avoid. Ideally, I want to use the shared version of libprotobuf for everything except the protoc-grpc-plugins (so that they don't need to find anything at runtime) - but I don't think that I can pass two different versions of protobuf to the grpc package (a static one for the plugins and a shared one for everything else) - or can conan figure this separation out, somehow? I could create a separate conan package that contains the protobuf compiler and the grpc plugins, but that doesn't contain any libraries. Then I could add this package as a tool requirement to convert proto-files to C++-code and add grpc- and protobuf-library packages as normal requirements. I don't see an easy solution. It would be great if at some point the tool chain file sets the environment variables, because this would solve my issues without any additional effort from the user. Thanks a lot for your patience - I fear that I will bother you with more questions in the future. |
Thanks for following up and closing
Don't hesitate to open new tickets or ping in old ones, sometimes we cannot follow up on everything, so resurfacing things is good too. Thanks! |
What is your question?
Hi,
I'm trying to build my own grpc recipe.
This works well, however, when I build its dependency protobuf as shared library and then try to use an executable contained in the grpc package (the grpc cpp plugin for protobuf) from within CMake, there is an error complaining that a shared library contained in the protobuf package cannot be found.
I tried to reduce it to an example that uses the grpc recipe from the conan center (cf. https://github.com/conan-io/conan-center-index/blob/master/recipes/grpc/all/conanfile.py).
I downloaded this recipe and forced protobuf to always be built as shared library (and grpc still as static library - in my opinion this shouldn't make a difference) by adding a line to the end of the
configure
step in the grpc recipe:I locally built this package by running
conan create . 1.54.3@test/test
.Then I set up a simple example:
conanfile.txt
CMakeLists.txt:
test.proto
When I try to build the cmake project I get the error:
I added the
virtualrunenv
generator to the list of generators in theconanfile.txt
with no success.I see that the grpc recipe uses
VirtualRunEnv
and also does someDYLD_LIBRARY
magic on MacOS.How can I correctly set the environment variables on Linux and Windows?
Thanks and best regards
oz
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: