Re: Adding own Library to project

König Patrick <Patrick.Koenig@...>

I solved it. I made a mistake while moving some of the function to the separated module.
While preparing the example I noticed, that some of the functions in the USB CDC_ACM example, which I used as a base for my project, were declared as static, which I did not notice.
When I added them to my lib, I did not see the static keyword and I forgot to remove it. This functions gave me the errors as described.

I apologize for my mistake and I want to thank all of you for your help.


-----Ursprüngliche Nachricht-----
Von: Bøe, Sebastian [mailto:Sebastian.Boe@...]
Gesendet: Donnerstag, 14. Juni 2018 14:39
An: König Patrick <Patrick.Koenig@...>; Li, Jun R <>; Patrick Boettcher <patrick.boettcher@...>
Cc: zephyr-devel@...; Sittkus Manuel <Manuel.Sittkus@...>
Betreff: Re: [Zephyr-devel] Adding own Library to project

As far as I am able to understand your description, this is expected to work.

Perhaps you could share a minimal patch to an existing sample to demonstrate when the linker error occurs.

From: devel@... <devel@...> on behalf of König Patrick <Patrick.Koenig@...>
Sent: Thursday, 14 June 2018 10:32:43 AM
To: Li, Jun R; Patrick Boettcher
Cc: zephyr-devel@...; Sittkus Manuel
Subject: Re: [Zephyr-devel] Adding own Library to project

Thanks a lot for your help. I have tried your suggested solution with the CMakeList. Unfortunately, this did not work for me. I got the linker errors as described in my initial mail.

Let me try to illustrate my problem in a bit more detail:

If I add two function to my main.c file, for example usb_send() and usb_receive(), my code works fine. Once I move these functions to independent files like usb_xyz.c for the source and usb_xyz.h for the headers and include the header file in the main.c file, I am no longer able to link my project.

Usually I just need to include usb_xyz.h to my main.c file and add the usb_xyz.c and usb_xyz.h to a Makefile. With Cmake however, I added the usb_xyz.c file to the CMakelist and included header file in my main.c file, which leaves me with linker errors, like undefined reference to usb_send() and usb_receive().
I checked the compiler output, and saw the following line: “Building C object CMakeFiles/app.dir/src/usb_xyz.c.obj”, which leads me to believe that the file was compiled.

I hope this example makes my issue a bit clearer. Basically I just want to create modular Code that I can reuse in other zephyr projects as well.



-----Ursprüngliche Nachricht-----
Von: Li, Jun R []
Gesendet: Mittwoch, 13. Juni 2018 16:59
An: Patrick Boettcher <patrick.boettcher@...>
Cc: König Patrick <Patrick.Koenig@...>; zephyr-devel@...; Sittkus Manuel <Manuel.Sittkus@...>
Betreff: Re: [Zephyr-devel] Adding own Library to project

That is true, this way doesn't support adding a driver module into the application since the app doesn't directly call anything from the driver. I'm wondering why driver modules in zephyr directory can be linked even without specifying dependency relationship. How is a driver module in Zephyr directory linked together?

On 6/13/18, 07:53, "devel@... on behalf of Patrick Boettcher" <devel@... on behalf of patrick.boettcher@...> wrote:

On Wed, 13 Jun 2018 14:45:43 +0000
"Li, Jun R" <> wrote:

> Hi Patrick,
> If you still want to keep your library (module), another way you can
> do is to add your library as the link dependency for the application
> library (app) by the following:
> target_link_libraries(app your_lib_name)

Well, this way of doing bears a whole of problems in some conditions.

While it works in probably most cases, including drivers in such a
library won't work.

Link-order sometimes messes up things as well if your library requires
zephyr functions from libraries where explicit dependencies was
not/could not be declared.

Sebastian is working on it, there is an issue on github's page for it.


Join to automatically receive all group messages.