Linking external libraries on NuttX

Some time ago I needed to link with ARM DSP library on NuttX to use FFT feature and I decided to document who I did it and some tricks to reduce the final binary size.

In fact to include a library all you need to do is add it to your board Make.defs. See a simple patch file to stm32f4discovery:

index 59aa60bf6b..5e6845c81c 100644
--- a/boards/arm/stm32/stm32f4discovery/scripts/Make.defs
+++ b/boards/arm/stm32/stm32f4discovery/scripts/Make.defs

+EXTRA_LIBS = "$(TOPDIR)/3rparty/libarmdsp.a"
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048

It means you need to create a “3rdpary” directory at root of nuttx/ and put your library there.

But after the compilation you will notice that your nuttx.bin binary will become very big. It happens because the linker will include all the functions in the library.

You can instruct it to include only the needed functions using this parameter with LDFLAGS:

LDFLAGS += --gc-sections

Now your binary will become way smaller

2 thoughts on “Linking external libraries on NuttX

  1. Dear Alan,
    Do you mean ARM CMSIS DSP library? If so, this is great news; we can include NN library as well, and these together simplify many AI applications including industrial predictive meintenance.
    Could you please expand this blog a little more (for us non-expert readers! ); such as how the directory structure should be, how the functions should be called etc.

  2. Hi Murat,
    Yes, it was the ARM CMSIS DSP library, I will include more details to let you and other people use it. But basically it is just a matter of following the trick and gave and using “git grep EXTRA_LIBS” to find the right place! 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s