-
Notifications
You must be signed in to change notification settings - Fork 970
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] CMakeDeps and inter-package dependencies when using shared libraries #16990
Comments
As a possible workaround target_link_libraries(engine_test
PRIVATE
engine
$<LINK_ONLY:log4cxx>
) That solves the linking problems, but something weird happens at the same time. Despite the
If I link Recipe of |
Hi @bukulin Thanks for your question and thanks specially for your detailed report. Can you please do a quick check? It would be in your test CMakeLists.txt: target_link_libraries(engine_test
PUBLIC engine ) This shouldn't have a bad impact, being the If this work, this is kind of a known issue, that happens in Linux like shared libraries (it doesn't happen in Windows shared libraries). It is kind of challenging to fix it in CMakeDeps at the moment with the current information we have, but we are working to improve and expand that information and planning an improved CMakeDeps generator (it will take some time, there are still other higher priorities) I think this was a very specific issue of the |
Hi @memsharded, Thank you for the quick reply! target_link_libraries(engine_test
PUBLIC engine ) Unfortunately the public dependency did not help here, I have got the same linker error and the same linker commandline. However, if target_link_libraries(engine PUBLIC log4cxx) , then the link step of
Thank you for the effort. We can live with a workaround that does not harm the required dependency chain. #16911 |
Maybe this is related to the Is the |
The from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
class engineRecipe(ConanFile):
name = "engine"
version = "1.0.0"
package_type = "library"
# Optional metadata
license = "MIT"
author = "Norbert Bukuli"
url = "-"
description = "middle engine library"
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": False,
"fPIC": True
}
# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*", "include/*"
def requirements(self):
self.requires("log4cxx/1.2.0")
def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
cmake_layout(self)
def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure(cli_args=["--graphviz", "deps.dot"])
cmake.build()
cmake.ctest(cli_args=["--output-on-failure"])
def package(self):
cmake = CMake(self)
cmake.install()
def package_info(self):
self.cpp_info.libs = ["engine"]
|
What is your question?
Hi!
I ran into a problem with
CMakeDeps
generator when shared libraries are used and the consuming project has a unit-test-like application. Trying to describe the situation as briefly as I could, but I have to dive deep. This might be due to my misunderstanding of the advanced dependency handling, but I try to do my best.So let's consider the following things:
*:shared=True
)math
substituted withlog4cxx
to have some more dependencies.Everything works correctly as described in the aforementioned video until I add a unit test to the
engine
package, just like that:engine/CMakeLists.txt
:engine/test/CMakeLists.txt
:So,
engine
depends privately onlog4cxx
andengine_test
depends onengine
, in turn.At this point when I try to compile the whole engine package, the link step of
engine_test
fails:Interestingly
liblog4cxx.so.15
is found but its dependencies not. The linker command line lacks here the library paths (-L
) (and RPATH definitions (-Wl,--rpath
)) of the transitive dependencies ofengine
, however they were present whenengine
library was built:When
engine
is built its dependencies are all come from the config files generated byCMakeDeps
however dependencies ofengine_test
handled internally by CMake.Everything works well, if
*:shared=False
, because in that case every static library is listed in the linker commandline when linkingengine_test
.This issue might be related to this one: #16911
What do I wrong? If it is possible, I try to use modern CMake and rely on
target_link_libraries
with local targets in this case. I suppose a workaround could be written, where I query all the link-time dependencies ofengine
and apply them toengine_test
but I try to avoid that.Any guidance will be highly appreciated. Unfortunately I cannot find corresponding points in the documentation.
Thank you in advance!
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: