-
Notifications
You must be signed in to change notification settings - Fork 994
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] "cpp_info.system_libs" and static linking of some system libs #17593
Comments
Thanks for your question
From what I understand reading the issue, this is not something new due to the migration. I think that
Quick question, you are using recipes and packages from ConanCenter, or are you using your own recipes? Or maybe at least building the binaries from a conan-center-index Github source repo fork? I am asking in case you could change the recipes to customize it. Regarding your attempt to remove the libraries from the consumer side CMake code, a couple of quick questions:
I'd try to add more logs to the cmake code, printing the targets, the target properties, whether the |
Hi @memsharded thanks for your reply. Sorry if I wasn't clear enough. We were using Makefiles with our own recipes for 3rd party libs in Conan v1. I believe there were no changes in the way Conan handles dependencies defined in A suggestion they gave us on a cmake forum is to put together a sysroot with the libraries we need and setup a cmake toolchain file to set CMAKE_SYSROOT variable. I don't now if that will make difference to Conan translates the "m" dependency properly to use the static version in its generated files and appends it to the interface link libraries of the targets it provides. I also tried a suggestion to use CMAKE_LINK_LIBRARY_USING_ to apply a pattern to redefine the way "-libm" is injected into the command line in the linker, but I don't know if it's due to an error in the way I tried to use it, I also didn't get the desired effect: https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.html Probably the solution of creating a repo, cloning the recipes for the dependencies we need and modifying them to remove the system lib definitions will be the alternative... |
Thanks for the clarification, now I understand, using Makefiles it is more clear how to manage flags and other stuff, things are more direct, with CMake not that much.
I think your original approach might still be doable, and it could have some advantages, as not having to fork and customize recipes, and also not having to manage a sysroot. It would need some expertise in CMake, and checking the internals of Conan generated .cmake files, but I have been successful with this small proof of concept:
The key is using for each package the Please let me know if this helps. |
@memsharded sorry for the delay in response. We had to hack the CXX Linker via set(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS>
<OBJECTS> -o <TARGET>
<LINK_LIBRARIES> -Wl,-Bstatic -lstdc++ -lm -Wl,-Bdynamic") In addition, to handle multiple We end doing this to prevent that: if(LINUX)
# force transitive dependencies of libs to libm be statically linked
add_library(m INTERFACE)
target_link_options(m INTERFACE "SHELL:-Wl,-Bstatic -lm -Wl,-Bdynamic")
endif() This generates the linking step as: gcc -m32 -march=pentium-mmx -m32 -Wl,-Bstatic -lm -Wl,-Bdynamic
...(*.o)
-o target
...(*.a)
-Wl,-Bstatic -lstdc++ -lm -Wl,-Bdynamic I don't have in-depth knowledge of CMake if there was a more orthodox approach to what was intended, but for now I've managed to overcome it this way and move on. Thank you very much for your support! |
What is your question?
Whe are porting some custom makefiles with Conan v1 to Cmake + Conan 2.
Some recipes, such as libpng, use this approach:
This raises an issue when you want to mix static linking of just some system libraries, such as the case of
libm
using-Wl,-Bstatic -lstdc++ -lm -Wl,-Bdynamic
The issue is that system libraries of the conan recipes that added it as a dependency are repeated in the linking command:
So the executable is linked dynamically to
libm
:We need to still statically link some system libraries like
libm
because we need to support old distros that have outdated libs.I tried to hack the dependencies in CMake to remove
-lm
like this but without success:Any idea about how can we deal with this issue?
Thanks
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: