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

Undefined reference errors when using External Library with k_msgq_* calls #31613

Closed
MaikVermeulen opened this issue Jan 26, 2021 · 6 comments
Closed
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@MaikVermeulen
Copy link
Contributor

MaikVermeulen commented Jan 26, 2021

Describe the bug
I made a very simple library that includes two functions that use the message queue. However, I get this linking error:
undefined reference to 'z_impl_k_msgq_put'

I think it's due to 'z_impl_k_msgq_put' being declared as extern and that affects the linking, but I haven't found a solution. I tried replacing the k_msgq_* functions with LOG_INF, and then it works just fine.

I'm trying to put some code into libraries so that we can share those with external parties, without sharing our source code with them.

To Reproduce
I have created a simple minimal example of the problem.

Expected behavior
A clean build.

Impact
I can't librarize Zephyr code that includes calls to the message queue (and possibly similar code), hence I can't provide external parties with the modules they need without sharing our source code.

Logs and console output
Rebuilding ‘zephyr/zephyr_prebuilt.elf’ from solution 'build' in configuration 'Common' Compiling 'empty_file.c' Linking 'zephyr_prebuilt.elf' B 1 MB 2.67% B 448 KB 1.74% lib/liblib.a(lib.c.obj): in function 'k_msgq_put'': undefined reference to 'z_impl_k_msgq_put' ld returned 1 exit status B 2 KB 4.30% Build failed

Environment (please complete the following information):

  • OS: Windows
  • nRF Connect SDK v1.4.99-dev1
@MaikVermeulen MaikVermeulen added the bug The issue is a bug, or the PR is fixing a bug label Jan 26, 2021
@nashif nashif added the priority: low Low impact/importance bug label Jan 26, 2021
@pabigot
Copy link
Collaborator

pabigot commented Jan 26, 2021

Please look at 6b720cb3c56a198db19b1884e78385cb7a392b00 for a possible fix.

@pabigot pabigot self-assigned this Jan 26, 2021
@MaikVermeulen
Copy link
Contributor Author

@pabigot This pointed me in the right direction, thank you.
Simply linking the kernel library resulted in a strong component cycle error, so I included the dummy library as PRIVATE:
zephyr_library_link_libraries(kernel) target_link_libraries(app PRIVATE lib)

Now it works. Thanks!

@danderson-presonus
Copy link

Hi, I'm having the same problem linking an external library that makes Zephyr kernel calls. I tried adding the line "zephyr_library_link_libraries(kernel)" in my CMakeLists.txt and changed "target_link_libraries(app PUBLIC pep)" to "target_link_libraries(app PRIVATE pep)" but this had no effect. I think I must be making the change in the wrong spot... help?

@MaikVermeulen
Copy link
Contributor Author

@danderson-presonus My CMakeLists.txt in the library folder containing the .a file:

zephyr_library_import(lib ${CMAKE_CURRENT_SOURCE_DIR}/liblib.a)
target_include_directories(app PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(lib INTERFACE kernel)
target_link_libraries(app PRIVATE lib)

@danderson-presonus
Copy link

Thanks! This got me up and running.

@CManigandan
Copy link

CManigandan commented May 18, 2022

Please look at 6b720cb3c56a198db19b1884e78385cb7a392b00 for a possible fix.

@pabigot I am not able to locate this fix. Can you help?

Thanks in Advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

5 participants