On Red Hat Linux 9 how to solve the following `/usr/bin/ld: cannot find -l` errors? Knowing that I installed the mentioned dependencies in `~/rpm/x86_64/`.

```bash
uv pip install iio==29
```
```
Using Python 3.14.4 environment at: .venv_x86-64
Resolved 1 package in 7ms
× Failed to build `iio==29`
├─▶ The build backend returned an error
╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit status: 1)

[stdout]
running bdist_wheel
running build
running build_py
running build_ext
building 'libiio' extension
cc -pthread -I /lustre/work/pdl16831/udlc74081/rpm/x86_64/usr/include/ -I
/lustre/work/pdl16831/udlc74081/rpm/x86_64/usr/include/libpng12/ -fPIC -Iiio
-I/usr/local/include -I/lustre/work/pdl16831/udlc74081/.cache/uv/builds-v0/.tmp8RWeRn/include
-I/lustre/work/pdl16831/udlc74081/.local/share/uv/python/cpython-3.14.4-linux-x86_64-gnu/include/python3.14 -c iio/iio.c -o
build/temp.linux-x86_64-cpython-314/iio/iio.o -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -g -O3 -Wall -O3
-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -DI_CAN_HAS_LIBWEBP
cc -pthread -shared -Wl,-z,noexecstack -Wl,--exclude-libs,ALL -I /lustre/work/pdl16831/udlc74081/rpm/x86_64/usr/include/ -I
/lustre/work/pdl16831/udlc74081/rpm/x86_64/usr/include/libpng12/ build/temp.linux-x86_64-cpython-314/iio/iio.o -L/usr/local/lib
-L/lustre/work/pdl16831/udlc74081/.local/share/uv/python/cpython-3.14.4-linux-x86_64-gnu/lib -lpng -ljpeg -ltiff -lwebp -o
build/lib.linux-x86_64-cpython-314/libiio.cpython-314-x86_64-linux-gnu.so

[stderr]
<string>:55: SyntaxWarning: "\." is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\."? A
raw string is also an option.
/usr/bin/ld: cannot find -lpng
/usr/bin/ld: cannot find -ljpeg
/usr/bin/ld: cannot find -ltiff
/usr/bin/ld: cannot find -lwebp
collect2: error: ld returned 1 exit status
error: command '/usr/bin/cc' failed with exit code 1


hint: Build failures usually indicate a problem with the package or the build environment
```
Jun 9, 9:20pm

The error /usr/bin/ld: cannot find -l<library> (e.g., -lpng, -ljpeg, -ltiff, -lwebp) means the linker (ld) cannot find the required static or shared libraries for libpng, libjpeg, libtiff, and libwebp. Even though you installed the dependencies in ~/rpm/x86_64/, the linker is not searching that directory for libraries.


Solution: Tell the Linker Where to Find the Libraries

1. Set LIBRARY_PATH and LD_LIBRARY_PATH

The linker (ld) and runtime linker use these environment variables to locate libraries.

bash
# For the current session (temporary)
export LIBRARY_PATH=~/rpm/x86_64/usr/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=~/rpm/x86_64/usr/lib:$LD_LIBRARY_PATH

# For permanent use, add these lines to your ~/.bashrc or ~/.bash_profile
echo 'export LIBRARY_PATH=~/rpm/x86_64/usr/lib:$LIBRARY_PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=~/rpm/x86_64/usr/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

Note:

  • LIBRARY_PATH is for compile-time linking.
  • LD_LIBRARY_PATH is for runtime linking.

2. Verify Library Files Exist

Ensure the .so (shared object) files for the missing libraries exist in ~/rpm/x86_64/usr/lib/:

bash
ls ~/rpm/x86_64/usr/lib/libpng*
ls ~/rpm/x86_64/usr/lib/libjpeg*
ls ~/rpm/x86_64/usr/lib/libtiff*
ls ~/rpm/x86_64/usr/lib/libwebp*

If they are missing, you need to install the development packages for these libraries (e.g., libpng-devel, libjpeg-turbo-devel, libtiff-devel, libwebp-devel) in your ~/rpm/x86_64/ directory.


3. Reinstall Dependencies in the Correct Location

If the libraries are missing, reinstall them in ~/rpm/x86_64/ using rpm or yum:

bash
# Example for libpng (adjust for your RPMs)
rpm -ivh --prefix=~/rpm/x86_64 libpng-devel-*.rpm
rpm -ivh --prefix=~/rpm/x86_64 libjpeg-turbo-devel-*.rpm
rpm -ivh --prefix=~/rpm/x86_64 libtiff-devel-*.rpm
rpm -ivh --prefix=~/rpm/x86_64 libwebp-devel-*.rpm

Note: Use --prefix to install RPMs in a custom directory.


4. Pass Linker Flags Explicitly

If the above doesn’t work, explicitly pass the library paths to the build process:

bash
# Set these before running `uv pip install iio==29`
export CFLAGS="-I~/rpm/x86_64/usr/include"
export LDFLAGS="-L~/rpm/x86_64/usr/lib -lpng -ljpeg -ltiff -lwebp"

uv pip install iio==29

5. Check for 32-bit vs 64-bit Mismatch

Ensure all libraries are 64-bit (since you’re using x86_64). If you accidentally installed 32-bit libraries, the linker will fail.

bash
file ~/rpm/x86_64/usr/lib/libpng.so*

Output should include ELF 64-bit.


6. Debugging the Linker

To see where the linker is searching for libraries:

bash
ld -v

or

bash
gcc -v -o /dev/null -lpng

Summary of Commands to Try

bash
# 1. Set library paths
export LIBRARY_PATH=~/rpm/x86_64/usr/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=~/rpm/x86_64/usr/lib:$LD_LIBRARY_PATH

# 2. Verify libraries exist
ls ~/rpm/x86_64/usr/lib/libpng* ~/rpm/x86_64/usr/lib/libjpeg* ~/rpm/x86_64/usr/lib/libtiff* ~/rpm/x86_64/usr/lib/libwebp*

# 3. Reinstall dependencies if missing
rpm -ivh --prefix=~/rpm/x86_64 libpng-devel-*.rpm libjpeg-turbo-devel-*.rpm libtiff-devel-*.rpm libwebp-devel-*.rpm

# 4. Retry installation
uv pip install iio==29

If the Issue Persists

  • Check if the libraries are named differently (e.g., libpng12.so instead of libpng.so).
  • Use ldconfig to update the shared library cache (if you have root access):
    bash
    sudo ldconfig
  • If you don’t have root access, stick with LIBRARY_PATH and LD_LIBRARY_PATH.
Jun 9, 9:20pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more