KasperskyOS Community Edition

Adding dynamic libraries to a KasperskyOS-based solution image

21 May 2024

ID shared_libraries_adding_to_image

To add dynamic libraries to the KasperskyOS-based solution image, use PACK_DEPS_COPY_ONLY ON, PACK_DEPS_LIBS_PATH, and PACK_DEPS_COPY_TARGET parameters in the CMake commands build_kos_qemu_image() and build_kos_hw_image().

Example:

set(RESOURCES ${CMAKE_SOURCE_DIR}/resources)

set(FSTAB ${RESOURCES}/fstab)

set(DISK_IMG ${CMAKE_CURRENT_BINARY_DIR}/ramdisk0.img)

set(RESOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../resources)

set(EXT4_PART_DIR ${CMAKE_CURRENT_BINARY_DIR}/../system_hdd)

set_target_properties(${vfs_ENTITY} PROPERTIES

EXTRA_ARGS

" - \"-f\"

- \"fstab\""

EXTRA_ENV

" ROOTFS: ramdisk0 / ext4 0"

${blkdev_ENTITY}_REPLACEMENT "${ramdisk_ENTITY};${sdcard_ENTITY}")

add_custom_target(copy-so)

add_custom_command(OUTPUT ${DISK_IMG}

COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_DIR}/rootdir ${EXT4_PART_DIR}

COMMAND mke2fs -v -d ${EXT4_PART_DIR} -t ext4 ${DISK_IMG} 40M

DEPENDS copy-so

COMMENT "Creating disk image '${DISK_IMG}' from files in '${EXT4_PART_DIR}' ...")

build_kos_hw_image(kos-image

...

IMAGE_FILES ${ENTITIES_LIST} ${FSTAB} ${DISK_IMG}

PACK_DEPS_COPY_ONLY ON

PACK_DEPS_LIBS_PATH ${EXT4_PART_DIR}/lib

PACK_DEPS_COPY_TARGET copylibs)

if(PLATFORM_SUPPORTS_DYNAMIC_LINKING)

add_dependencies(copy-so copylibs)

endif()

The solution program-dependent dynamic libraries are added to a storage device image (for example, one with an ext4 file system) that will be included into the solution image.

Dynamic libraries that are loaded into memory by calling the dlopen() function of the POSIX interface are not added to the solution image.

The build system does the following:

  • Searches for dynamic libraries and copies these libraries to the directory whose path is specified in the PACK_DEPS_LIBS_PATH parameter of the CMake commands build_kos_qemu_image() and build_kos_hw_image(). (To ensure that the found dynamic libraries are included in the storage device image, this directory must reside in the file system that will be put into the storage device image.)
  • Creates a storage device image that includes the directory containing the dynamic libraries.

    To create a storage device image, use the CMake command add_custom_command(). The target specified in the DEPENDS parameter of the CMake command add_custom_command(), indicates that a storage device image is created. The target specified in the PACK_DEPS_COPY_TARGET parameter of the CMake commands build_kos_qemu_image() and build_kos_hw_image(), indicates that dynamic libraries are copied. To make sure that the storage device image is created only after the dynamic libraries are fully copied, use the CMake command add_dependencies().

  • Adds the storage device image to the solution image.

    To add the storage device image to the solution image, specify the full path to the storage device image in the IMAGE_FILES parameter of the CMake commands build_kos_qemu_image() and build_kos_hw_image().

Did you find this article helpful?
What can we do better?
Thank you for your feedback! You're helping us improve.
Thank you for your feedback! You're helping us improve.