how to conditionally link a static library in Zephyr?


Li, Jun R
 

Hi there,

I’m trying to build my zephyr app with a static library which is not provided with its source code. I can achieve the goal by adding the following two lines in my project’s Makefile:

 

export LDFLAGS_zephyr += -L$(SOURCE_DIR)/mylib/

export ALL_LIBS += mylib

 

However, I want to get the static library linked only when a specific macro is defined, like below

 

Ifeq ($(CONFIG_ENABLE_MYLIB),y)

export LDFLAGS_zephyr += -L$(SOURCE_DIR)/mylib/

export ALL_LIBS += mylib

endif

 

 

Here `CONFIG_ENABLE_MYLIB` is a macro defined in a Kconfig file somewhere.

 

However, the static library can’t be linked if I used the conditional option even though the macro CONFIG_ENABLE_MYLIB is enabled in my “prj.conf”.

 

So, I’m wondering if anybody has done the similar work and can you share the experience? Thank you very much!

 

Regards,

Jun

 


Paul Sokolovsky
 

Hello,

On Sun, 3 Sep 2017 06:28:52 +0000
"Li, Jun R" <jun.r.li@...> wrote:

Hi there,
I’m trying to build my zephyr app with a static library which is not
provided with its source code. I can achieve the goal by adding the
following two lines in my project’s Makefile:

export LDFLAGS_zephyr += -L$(SOURCE_DIR)/mylib/
export ALL_LIBS += mylib

However, I want to get the static library linked only when a specific
macro is defined, like below

Ifeq ($(CONFIG_ENABLE_MYLIB),y)
export LDFLAGS_zephyr += -L$(SOURCE_DIR)/mylib/
export ALL_LIBS += mylib
endif


Here `CONFIG_ENABLE_MYLIB` is a macro defined in a Kconfig file
somewhere.
Well, that's not specific enough. It's not enough to define a config
option "in a Kconfig file somewhere" for it to be actually available in
Zephyr build process. Nor you explain which Makefile contains
ifeq/endif snippet above.

However, the static library can’t be linked if I used the conditional
option even though the macro CONFIG_ENABLE_MYLIB is enabled in my
“prj.conf”.
With the (sparse) info above, I'd suggest checking that
outdir/$BOARD/.config actually contains CONFIG_ENABLE_MYLIB=y.


So, I’m wondering if anybody has done the similar work and can you
share the experience? Thank you very much!

Regards,
Jun


--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog


Nashif, Anas
 

Hi,

The Kconfig options (macro) you define need to be included (sourced) in the overall Kconfig structure of zephyr, just adding an option to prj.conf does not give you what you want. This is possible and there are a few examples for doing this, see

 

tests/benchmarks/object_footprint/: This test uses local Kconfig variables

samples/application_development/: A few samples for linking external libraries and 3rd party code.

 

Anas

 

From: zephyr-devel-bounces@... [mailto:zephyr-devel-bounces@...] On Behalf Of Li, Jun R
Sent: Sunday, September 3, 2017 2:29 AM
To: zephyr-devel@...
Subject: [Zephyr-devel] how to conditionally link a static library in Zephyr?

 

Hi there,

I’m trying to build my zephyr app with a static library which is not provided with its source code. I can achieve the goal by adding the following two lines in my project’s Makefile:

 

export LDFLAGS_zephyr += -L$(SOURCE_DIR)/mylib/

export ALL_LIBS += mylib

 

However, I want to get the static library linked only when a specific macro is defined, like below

 

Ifeq ($(CONFIG_ENABLE_MYLIB),y)

export LDFLAGS_zephyr += -L$(SOURCE_DIR)/mylib/

export ALL_LIBS += mylib

endif

 

 

Here `CONFIG_ENABLE_MYLIB` is a macro defined in a Kconfig file somewhere.

 

However, the static library can’t be linked if I used the conditional option even though the macro CONFIG_ENABLE_MYLIB is enabled in my “prj.conf”.

 

So, I’m wondering if anybody has done the similar work and can you share the experience? Thank you very much!

 

Regards,

Jun