could not found static link lib even with lib prefix under linux
22:05 06 Jan 2026

I have a rust project that used a lib called synctex_parser, this is the path I put the lib src/so, the lib with lib prefix src/so/libsynctex_parser.so. when I build this project under macos, it works fine, when I build the lib under linux, shows error:

#11 287.9   = note: some arguments are omitted. use `--verbose` to show all linker arguments
#11 287.9   = note: /usr/bin/ld: cannot find -lsynctex_parser: No such file or directory
#11 287.9           collect2: error: ld returned 1 exit status
#11 287.9           
#11 287.9 
#11 287.9 warning: `cv-render` (bin "cv-render") generated 83 warnings
#11 287.9 error: could not compile `cv-render` (bin "cv-render") due to 1 previous error; 83 warnings emitted
#11 ERROR: process "/bin/sh -c CARGO_HTTP_MULTIPLEXING=false cargo build --release" did not complete successfully: exit code: 101
------
 > [builder 3/3] RUN CARGO_HTTP_MULTIPLEXIN

I have tried to add script in buld.rs like this:

use std::env;
use std::path::Path;

fn main() {
    // If a prebuilt native library exists under `src/so`, add that to the link search path
    let manifest = env::var("CARGO_MANIFEST_DIR").unwrap();
    let so_dir = Path::new(&manifest).join("src/so");
    if so_dir.exists() {
        let so_dir_str = so_dir.display().to_string();
        println!("cargo:rustc-link-search=native={}", so_dir_str);
        
        // On macOS, also set rpath so the library can be found at runtime
        #[cfg(target_os = "macos")]
        {
            println!("cargo:rustc-link-arg=-Wl,-rpath,{}", so_dir_str);
        }

        #[cfg(target_os = "linux")]
        {
            println!("cargo:rustc-link-arg=-Wl,-rpath,{}", so_dir_str);
        }
    }

    // In case some environments need an explicit link-lib directive
    println!("cargo:rustc-link-lib=synctex_parser");
}

did not fixed this issue. This is the full dockerfile:

ARG BASE_IMAGE=dolphinjiang/rust-musl-builder:latest
FROM ${BASE_IMAGE} AS builder
ADD --chown=rust:rust . ./
RUN CARGO_HTTP_MULTIPLEXING=false cargo build --release

# https://github.com/kjarosh/latex-docker
FROM kjarosh/latex:2023.1
LABEL org.reddwarf.image.authors="jiang@gmail.com"

ENV LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8 \
    TZ=Asia/Shanghai

WORKDIR /app
ENV ROCKET_ADDRESS=0.0.0.0
COPY --from=builder /home/rust/src/settings-production.toml /app/settings.toml
COPY --from=builder /home/rust/src/script /app/
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/cv-render /app/
RUN mkdir -p /usr/share/fonts/ && mkdir -p /app/config/ && mkdir -p /root/.ssh
COPY --from=builder /home/rust/src/log4rs.yaml /app/
RUN tlmgr update --self && tlmgr install ctex moderncv fontawesome5 fontawesome nth\ 
    academicons multirow arydshln titlesec enumitem makecell relsize\
    tcolorbox environ tikzfill csquotes xifthen ifmtarg tex-gyre && \
    apk update && \
    apk add rsync openssh sshpass fontconfig && \
    chmod +x cv-render && texhash && fc-cache -f
CMD ["./cv-render"]

Am I missing something? what should I do to fixed this issue.

rust cargo