add zephyr library to external lib

I tried using the 'externallib' sample with toolchain 2.7.0 and SDK 2.6.1, and it works fine.

However, if I add something like #include <zephyr/kernel.h> in 'mylib.h', the compiler throws an error.
I have tried including the Zephyr library directories, adding a CMakeLists.txt along with the 'Makefile', but I was
unable to get the compilation to work. In my external library, I actually need to include some parts of the Zephyr libraries as well.

examples:

PREFIX ?= .
OBJ_DIR ?= $(PREFIX)/obj
LIB_DIR ?= $(PREFIX)/lib

CC = /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
AR = /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-ar
CFLAGS = -fPIC -Wall -I/opt/nordic/ncs/v2.6.1/zephyr/include -I/Users/marinosilvio/Documents/Static_library/external_lib/build/zephyr/include/generated -I/opt/nordic/ncs/v2.6.1/zephyr/soc/arm/nordic_nrf/nrf52 -I/opt/nordic/ncs/v2.6.1/zephyr/lib/libc/common/include -I/opt/nordic/ncs/v2.6.1/zephyr/soc/common/nordic_nrf/. -I/opt/nordic/ncs/v2.6.1/zephyr/soc/arm/nordic_nrf/common/. -I/opt/nordic/ncs/v2.6.1/nrf/include -I/opt/nordic/ncs/v2.6.1/nrf/tests/include -I/opt/nordic/ncs/v2.6.1/modules/hal/cmsis/CMSIS/Core/Include -I/opt/nordic/ncs/v2.6.1/zephyr/modules/cmsis/. -I/opt/nordic/ncs/v2.6.1/modules/hal/nordic/nrfx -I/opt/nordic/ncs/v2.6.1/modules/hal/nordic/nrfx/drivers/include -I/opt/nordic/ncs/v2.6.1/modules/hal/nordic/nrfx/mdk -I/opt/nordic/ncs/v2.6.1/zephyr/modules/hal_nordic/nrfx/. -I/opt/nordic/ncs/v2.6.1/modules/debug/segger/SEGGER -I/opt/nordic/ncs/v2.6.1/modules/debug/segger/Config -DKERNEL -D__ZEPHYR__=1 -D_FORTIFY_SOURCE=1 -D__LINUX_ERRNO_EXTENSIONS__ -D_POSIX_C_SOURCE=200809 -DPICOLIBC_LONG_LONG_PRINTF_SCANF -D__PROGRAM_START -DNRF52840_XXAA -fno-strict-aliasing -Os -imacros /Users/marinosilvio/Documents/Static_library/external_lib/build/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=/opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros /opt/nordic/ncs/v2.6.1/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wformat -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/Users/marinosilvio/Documents/Static_library/external_lib=CMAKE_SOURCE_DIR -fmacro-prefix-map=/opt/nordic/ncs/v2.6.1/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/opt/nordic/ncs/v2.6.1=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -std=c99 -isystem/opt/nordic/ncs/v2.6.1/zephyr/lib/libc/common/include

ifeq ($(findstring Windows, $(OS)),Windows)
    DEL := rmdir /S /Q
    MKDIR := mkdir
else
    DEL := rm -rf
    MKDIR := mkdir -p
endif

all:
    -$(MKDIR) "$(OBJ_DIR)"
    -$(MKDIR) "$(LIB_DIR)"
    $(CC) -c $(CFLAGS) -MD -Iinclude src/mylib.c -o $(OBJ_DIR)/mylib.o
    $(AR) -rcs $(LIB_DIR)/libmylib.a $(OBJ_DIR)/mylib.o

clean:
    $(DEL) "$(OBJ_DIR)" "$(LIB_DIR)"


I would appreciate any suggestions.

Thank you.

BABOS

Related