I wants to add a zlib library for compression and decompression a stream of data.I was cross compiled the zlib and generate the libz.so and libz.a file.
I wants to add a zlib library for compression and decompression a stream of data.I was cross compiled the zlib and generate the libz.so and libz.a file.
Hi,
There is already support for compression and decompression in nRF Connect SDK through the LZ4 library. If you are free to choose compression algorithm then this library is definitely the recommendation. See the LZ4 sample found at <sdk folder>\zephyr\samples\compression\lz4\ for reference.
For building and including precompiled (external static) libraries, please have a look at the External Library sample found at <sdk folder>\zephyr\samples\application_development\external_lib\ for reference.
Regards,
Terje
In lz4 compression method the compression ration was lesser compare to zlib so we want zlib method.Here i am cross compiled zlib with arm-none-eabi toolchain and generated the shared object file(.so) .I added the .so file in external libaray like
And my project folder looks like this:
├--- CMakeLists.txt
├--- prj.conf
├--- src
└-- main.c
└--- externlib
└-- inc
└--zlib.h and zconf.h #header file to be included
└-- lib
└-- libz.a #library to be added
└-- libz.so #library to be added
While i am adding my library in cmakelist i got some error like this
Building hello_world /bin/sh -c west build --build-dir /home/mysticp0004/Desktop/Linux_Study/hello_world/build /home/mysticp0004/Desktop/Linux_Study/hello_world [0/1] Re-running CMake... Loading Zephyr default modules (Zephyr base (cached)). -- Application: /home/mysticp0004/Desktop/Linux_Study/hello_world -- CMake version: 3.20.5 -- Cache files will be written to: /home/mysticp0004/.cache/zephyr -- Zephyr version: 3.3.99 (/home/mysticp0004/NCS/v2.4.0/zephyr) -- Found west (found suitable version "1.0.0", minimum required is "0.7.1") -- Board: nrf52840dongle_nrf52840 -- Found host-tools: zephyr 0.16.0 (/home/mysticp0004/NCS/toolchains/1f9b40e71a/opt/zephyr-sdk) -- Found toolchain: zephyr 0.16.0 (/home/mysticp0004/NCS/toolchains/1f9b40e71a/opt/zephyr-sdk) -- Found BOARD.dts: /home/mysticp0004/NCS/v2.4.0/zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts -- Generated zephyr.dts: /home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr/zephyr.dts -- Generated devicetree_generated.h: /home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr/include/generated/devicetree_generated.h -- Including generated dts.cmake file: /home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr/dts.cmake Parsing /home/mysticp0004/NCS/v2.4.0/zephyr/Kconfig Loaded configuration '/home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr/.config' No change to configuration in '/home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr/.config' No change to Kconfig header in '/home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr/include/generated/autoconf.h' CMake Warning at /home/mysticp0004/NCS/v2.4.0/zephyr/subsys/usb/device/CMakeLists.txt:22 (message): CONFIG_USB_DEVICE_VID has default value 0x2FE3. This value is only for testing and MUST be configured for USB products. CMake Warning at /home/mysticp0004/NCS/v2.4.0/zephyr/subsys/usb/device/CMakeLists.txt:28 (message): CONFIG_USB_DEVICE_PID has default value 0x100. This value is only for testing and MUST be configured for USB products. CMake Warning at /home/mysticp0004/NCS/v2.4.0/zephyr/CMakeLists.txt:838 (message): No SOURCES given to Zephyr library: lib__libc__common Excluding target from build. -- Configuring done -- Generating done -- Build files have been written to: /home/mysticp0004/Desktop/Linux_Study/hello_world/build [1/14] Generating misc/generated/syscalls.json, misc/generated/struct_tags.json [2/14] Generating linker_zephyr_pre0.cmd [3/14] Generating linker_zephyr_pre1.cmd [4/14] Linking C executable zephyr/zephyr_pre0.elf FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map : && ccache /home/mysticp0004/NCS/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf -fuse-ld=bfd -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=/home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/minimal/liblib__libc__minimal.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a zephyr/boards/boards/arm/nrf52840dongle_nrf52840/libboards__arm__nrf52840dongle_nrf52840.a zephyr/drivers/usb/device/libdrivers__usb__device.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/hwinfo/libdrivers__hwinfo.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L"/home/mysticp0004/NCS/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m/nofp" -L/home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr -lgcc ../externlib/lib/libz.so zephyr/arch/common/libisr_tables.a -mcpu=cortex-m4 -mthumb -mabi=aapcs -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn -Wl,-no-pie /home/mysticp0004/NCS/v2.4.0/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/soft-float/no-interrupts/libnrf_cc310_platform_0.9.17.a && cd /home/mysticp0004/Desktop/Linux_Study/hello_world/build/zephyr && /home/mysticp0004/NCS/toolchains/1f9b40e71a/usr/local/bin/cmake -E echo /home/mysticp0004/NCS/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: attempted static link of dynamic object `../externlib/lib/libz.so' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. FATAL ERROR: command exited with status 1: /home/mysticp0004/NCS/toolchains/1f9b40e71a/usr/local/bin/cmake --build /home/mysticp0004/Desktop/Linux_Study/hello_world/build
my cmakelist was looks like this.
cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(hello_world) target_sources(app PRIVATE src/main.c) set(CMAKE_PREFIX_PATH "externlib") find_package(ZLIB REQUIRED) include_directories(${ZLIB_INCLUDE_DIRS}) set(ZLIB_LIBRARY "externlib/lib/libz.a") set(ZLIB_INCLUDE_DIR "externlib/include") target_link_libraries(app PRIVATE ${ZLIB_LIBRARIES})
Hi,
Zephyr does not support dynamically linked (shared) libraries, so the fact that your build output contains ../externlib/lib/libz.so
means that something is wrong. You should not include .so
files in your project, as those are dynamically linked libraries. Rather you should use .a
files, which are statically linked.
Please note that any existing library may need modification in order to work with Zephyr. If you take, for instance, a library made for an operating system such as GNU/Linux or Windows, it may use features and system calls that are simply not available in Zephyr. For instance you may need changes for working with heap memory. For finding resources and getting help with porting libraries to Zephyr I recommend having a look at the official Zephyr resources.
Please also note that there are several things to consider when choosing a compression library, including size of the library itself, compression and decompression speed, compression rate, and possibility to configure the library according to your needs. Specifically the ported LZ4 library used in Zephyr is suited for microcontrollers, is fast, and can do dictionary compression (for better compression performance.) See the LZ4 fork for Zephyr at https://github.com/zephyrproject-rtos/lz4 for more details.
Regards,
Terje