conan-io / conan

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

[question] Trouble linking dependency library package which depends on precompiled libraries. #11032

Open aarangop opened 2 years ago

aarangop commented 2 years ago

Hello, I have been trying with success to package some precompiled libraries. However, there is a behavior I don't understand. Maybe someone can shed some light on this.

I wanted to package some precompiled libraries (SimConnect), so that they can be consumed by other packages. I have created two packages, one which links to the precompiled libraries and the other one which consumes the first one:

This seems to work well, however, if simconnect_package provides some functionality, for instance, if I wanted to make a wrapper for the SimConnect libraries, the simconnect_package library itself is not found when building simconnect_package_consumer. So, from simconnect_package_consumer I have access to the precompiled libraries (thanks to simconnect_package) but I have no access to simconnect_package functionality itself.

I am using the cmake_find_package_multi generator. After a few hours of trying to make things work, I found out that while the precompiled libraries are found by find_package(simconnect_package) in the simconnect_package_consumer's CMakeLists file, the simconnect_package libraries itself are not found. Hence, they aren't linked and so, any functions referenced in the consumer package result in unresolved external symbols.

I have made a working sample here:

The precompiled simconnect libraries are found within the repo. These are freely available through the Prepar3D SDK.

This are my settings (default profile):

[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
build_type=Release
[options]
[conf]
[build_requires]
[env]

And this is the list of commands that I've used (after cloning repo and cd'ing to it):

cd .\simconnect_package\
mkdir build
cd build
conan install ..
conan create ..
cd ../../
cd .\simconnect_package_consumer\
mkdir build
cd build
conan install .. --build=missing
conan build ..
.\Release\simconnect_consumer.exe

The exe should run, but you should get a message reporting failure to open connection, since I assume you don't have Prepar3D v5 on your machine.

The simconnect_package package is successfully exported, simconnect_package_consumer is successfully built and I can run the compiled simconnect_consumer.exe, which uses the precompiled libraries.

So, maybe someone can explain this behavior? Why are the simconnect_package libraries not found by find_package() but the precompiled libraries are?

memsharded commented 2 years ago

Hi @aarangop

Some initial quick feedback while checking the issue:

I will investigate a bit further your code and try to reproduce. Thanks very much for your elaborated description and putting together a repo with the code!

memsharded commented 2 years ago

I have done a review to your repo in https://github.com/aarangop/simconnect_packaging_working_example/pull/1

aarangop commented 2 years ago

Hi, thanks for the feedback! I will slim down the recipes with my actual code. I'll give it a try with CMakeDeps, which I saw is part of what you reviewed in the repo. As I mentioned, I can get things to work, I just can't link to the simconnect_package library, if there are any news on that front I'll be interested to know about them, I'll see if I can keep an eye open.

...And thanks for the work with Conan! I've found it really useful and I can see you make a great effort to listen to the users and to keep developing it.

memsharded commented 2 years ago

As I mentioned, I can get things to work, I just can't link to the simconnect_package library, if there are any news on that front I'll be interested to know about them, I'll see if I can keep an eye open.

Sure, but please note there is a difference in getting something that works, and following some good practices that will really help you scale faster and more easily, with less work. In your repo there were some things that aren't best practices, and that can easily come back to you to bite you later in ways you don't expect. If you want to know more about those, feel free to respond to my PR to your repo, and we can talk there.

Let us know how it goes with the CMakeDeps generator.

And thanks for the work with Conan! I've found it really useful and I can see you make a great effort to listen to the users and to keep developing it.

Thanks for your kind words! Happy to know that it is being useful :)