Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 803 of 93611. Introduction to Embedded LinuxFree lesson

Managing Shared Libraries and Dynamic Linkers

Configure the root filesystem to include necessary C libraries and dynamic linkers to ensure cross-compiled binaries execute correctly on the target.

In this lesson, you will learn how to resolve dependency requirements for cross-compiled binaries by correctly deploying C libraries and dynamic linkers into your embedded root filesystem.

When you compile a user-space application using a toolchain, the resulting binary is rarely "statically linked" (containing all library code within itself) because that would waste precious flash storage. Instead, most binaries are "dynamically linked," meaning they depend on external shared libraries (like libc.so) and a dynamic linker (like ld-linux.so) to resolve symbols at runtime.

The Role of the Dynamic Linker

When you execute a binary on your target, the kernel hands off control to the dynamic linker specified in the ELF header. You can inspect this path on your host using readelf:

$ arm-linux-gnueabihf-readelf -l my_app | grep interpreter
[Requesting program interpreter: /lib/ld-linux-armhf.so.3]

If the file at that exact path does not exist on your target's root filesystem, or if the dependent libraries (found via ldd my_app) are missing, the kernel will return a cryptic "file not found" error, even if the binary file itself is present.

Configuring the Filesystem

To ensure your binaries run, you must mirror the necessary environment:

  1. Locate the dynamic linker: Identify the loader from your cross-compilation toolchain and copy it to the target’s /lib/ directory. It must match the path expected by the binary.
  2. Populate shared objects: Use ldd on your host binary to list dependencies. You must copy these .so files from your toolchain’s sysroot to the target’s /lib/ or /usr/lib/ directories.
  3. Permissions: Ensure the dynamic linker has execute permissions (chmod +x), or the kernel will refuse to load it.

For minimal systems, you can automate this by using ${CROSS_COMPILE}readelf -d to inspect the NEEDED entries and recursively copying the required libraries from your toolchain sysroot. Neglecting to match the exact version or architecture of these libraries is a common cause of "Segmentation Fault" or "Exec format error" during the transition from bootloader to user space.

Key Takeaway: A dynamically linked binary requires its specific loader and all dependency chains to be present at the exact file paths expected by the ELF header, or the binary will fail to initialize at runtime.