Skip to content
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

External libs are always placed after libkernel on linker command line #86657

Open
jasal82 opened this issue Mar 5, 2025 · 2 comments
Open
Assignees
Labels
area: Build System bug The issue is a bug, or the PR is fixing a bug

Comments

@jasal82
Copy link

jasal82 commented Mar 5, 2025

Describe the bug

I want to link external static libraries to my app target. These external libraries were built with Conan and use Zephyr kernel functions. I made sure that the Conan build uses the same (generated) headers as the Zephyr build itself. I added the CMakeDeps generator path to the Zephyr build by adding a -DCMAKE_PREFIX_PATH argument so that I can use the find_package macros to discover the Conan imported library targets inside my Zephyr app CMakeLists. Now the problem is that when I do

find_package(conanlib1 CONFIG REQUIRED)
target_link_libraries(app conanlib1::conanlib1)

the Conan library always ends up after the zephyr/kernel/libkernel.a in the linker command line. That makes the linker drop the unused symbols from libkernel.a which are then reported as undefined symbols when linking conanlib1.

I already tried a myriad of things to get this running somehow, including trying to understand the zephyr cmake internals, but nothing seems to work. I found a suggestion to make the imported lib link against zephyr or zephyr_interface, but that didn't help either.

To Reproduce

You can reproduce this with the external_lib sample project. There the external lib is also added after the kernel lib on the command line.

Expected behavior

The external libs are placed after the whole-archive section but before libkernel.a.

Impact

Showstopper for our Conan/Zephyr integration project.

Logs and console output

n/a

Environment (please complete the following information):

  • OS: Linux
  • Zephyr 4.1.0-rc3, SDK 0.17.0

Additional context

n/a

@jasal82 jasal82 added the bug The issue is a bug, or the PR is fixing a bug label Mar 5, 2025
Copy link

github-actions bot commented Mar 5, 2025

Hi @jasal82! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

@jasal82
Copy link
Author

jasal82 commented Mar 6, 2025

I found a solution that seems to fix the problem. If I do

def package_info(self):
  if self.settings.os == "Zephyr":
    self.cpp_info.system_libs.append("kernel")

in my conanfile.py the CMakeDeps generator will add kernel at the end of the INTERFACE_LINK_LIBRARIES for my library and then the linker command in Zephyr gets an extra zephyr/kernel/libkernel.a after the Conan library. I found no way to do that in the Zephyr CMakeLists, however. Do you think that this solution is robust enough or is there a chance that the kernel CMake target is renamed in the future? This would break our build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

3 participants