How to include existing static library (.a) to application link line?

It still works the way I described it here. I only ever got it to work with the modular build though, so please make sure export MODULAR=y is set.

The library itself could always be the problem as well. I suggest creating a really simple C library first to try it out:

awesome.c
double awesome_call() {
   return 2.0;
}

awesome.h
#ifndef __AWESOME__
#define __AWESOME__
double awesome_call();
#endif 

to compile, use the same build flag as in build/arm-tools.mk

arm-none-eabi-gcc  -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -c awesome.c -o awesome.o
arm-none-eabi-ar  rcs libawesome.a awesome.o

Then in modules/photon/user-part/makefile add your static library (take care of correct path)

LDFLAGS += -Wl,--whole-archive $(PROJECT_ROOT)/hal/src/photon/lib/STM32F2xx_Peripheral_Libraries.a $(PROJECT_ROOT)/../awesome_lib/libawesome.a -Wl,--no-whole-archive

Then in build/module.mk add your include path (or dump the header in any already known path)

INCLUDE_DIRS += $(addsuffix /src,$(MODULE_LIBSV2))
INCLUDE_DIRS += $(PROJECT_ROOT)/../awesome_lib/

Then you can use

extern "C" {
#include "awesome.h"
}

in any file and you are good to go.

Good luck. Should work with c++ as well.

2 Likes