openwrt / openwrt/packages

rust: need a way to pass ldflags to rustc?

Open
#24,375 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Makefile
Stars
4.6k
Forks
4k
Avg merge
3d 12h
Merged PRs (30d)
134

Description

Maintainer: @lu-zero @1715173329
Environment: x86_64, glibc

Description:

I wanted to compile einat , but somehow rustc cannot found libintl at the end.

I have tried everything

TARGET_CFLAGS += -Xlinker -rpath=$(STAGING_DIR)/usr/lib/libintl-full/lib
or
TARGET_LDFLAGS += -L$(STAGING_DIR)/usr/lib/libintl-full/lib -lintl
or
export LD_LIBRARY_PATH=$(STAGING_DIR)/usr/lib/libintl-full/lib

but rustc still didn't picked it up.

   Compiling einat v0.1.2 (/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3)
     Running `rustc --crate-name build_script_build --edition=2021 build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C overflow-checks=on --cfg 'feature="default"' --cfg 'feature="ipv6"' -C metadata=13037c25982734ec -C extra-filename=-13037c25982734ec --out-dir /home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/einat-13037c25982734ec -C linker=x86_64-openwrt-linux-gnu-gcc -C strip=symbols -L dependency=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps --extern libbpf_cargo=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/liblibbpf_cargo-fc7173ecf7072a22.rlib -L native=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/libbpf-sys-de20753a55c71e06/out -L native=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps -L native=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release -L native=/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib -L native=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/vsprintf-f6a1be3b8a629995/out`
error: linking with `x86_64-openwrt-linux-gnu-gcc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/bin:/home/user/works/openwrt/staging_dir/hostpkg/bin:/home/user/works/openwrt/staging_dir/toolchain-x86_64_gcc-14.1.0_glibc/bin:/home/user/works/openwrt/staging_dir/toolchain-x86_64_gcc-14.1.0_glibc/bin:/home/user/works/openwrt/staging_dir/host/bin:/home/user/works/openwrt/staging_dir/host/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "x86_64-openwrt-linux-gnu-gcc" "-m64" "/home/user/works/openwrt/tmp/rustca9rJSt/symbols.o" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/einat-13037c25982734ec/build_script_build-13037c25982734ec.build_script_build.900026c213c08482-cgu.0.rcgu.o" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/einat-13037c25982734ec/build_script_build-13037c25982734ec.2kuwii56gzittnew.rcgu.o" "-Wl,--as-needed" "-L" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps" "-L" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/libbpf-sys-de20753a55c71e06/out" "-L" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps" "-L" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release" "-L" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/vsprintf-f6a1be3b8a629995/out" "-L" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/liblibbpf_cargo-fc7173ecf7072a22.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libcargo_metadata-77b698b469ccad23.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libserde_json-d18e1952940c9d6c.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libitoa-c99bf860a1243733.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libryu-42733ab1749368f9.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libthiserror-aa231274481bae73.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libcargo_platform-c20f7cad56b30019.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libcamino-a1fd712e042bd596.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libmemmap2-73fca818d05ca4c9.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/liblibbpf_rs-12af648727bedc4e.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libvsprintf-52f5d1afc74d566c.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/liblibc-a50be116079b6680.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/liblibbpf_sys-6ce4fe8ed806fc57.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libsemver-d9af4a6bbaa40b09.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libserde-73abfa3b10e52ca3.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libregex-662c0e78adcebbf3.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libregex_automata-e8e6e085a55c8ab3.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libregex_syntax-f1d457fe75bcbfd6.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libtempfile-e4833a2ad6c4f429.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libfastrand-906c084e5ef6039e.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/librustix-4d3b20d2716f8231.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libbitflags-3a495cf5bbfede0b.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/liblinux_raw_sys-ba02cfb0a81adfba.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libcfg_if-1c8851ce38e8a7c1.rlib" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/libanyhow-0deb8dd3c263e7fc.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-18d1c84127d04dc5.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-bc53c6e5d5f4111f.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-a79bc22e6ae9ee83.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-9c256084533d6dad.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-e53b44d64d10bb35.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-9d0b3274a5b15e82.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-b0fb619b58a6601a.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-1319f451087d6793.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e7ba5787d3fb181b.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-e23167ed65317fed.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-52af0786d05d61a5.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-28f9d348427e8d43.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-689892118ddcc60e.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-a1f86f0be6e775e6.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-cbc93ea126f55c98.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-390f90785cbfdde3.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-aded7817e4ea9283.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-6c16e1294e732b84.rlib" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-a8a94ae78107d089.rlib" "-Wl,-Bdynamic" "-lelf" "-lz" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/einat-13037c25982734ec/build_script_build-13037c25982734ec" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-all" "-nodefaultlibs"
  = note: /home/user/works/openwrt/staging_dir/toolchain-x86_64_gcc-14.1.0_glibc/lib/gcc/x86_64-openwrt-linux-gnu/14.1.0/../../../../x86_64-openwrt-linux-gnu/bin/ld: warning: libintl.so.8, needed by /home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/usr/lib/libelf.so, not found (try using -rpath or -rpath-link)
          /home/user/works/openwrt/staging_dir/toolchain-x86_64_gcc-14.1.0_glibc/lib/gcc/x86_64-openwrt-linux-gnu/14.1.0/../../../../x86_64-openwrt-linux-gnu/bin/ld: /home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/usr/lib/libelf.so: undefined reference to `libintl_dgettext'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

error: could not compile `einat` (build script) due to 1 previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name build_script_build --edition=2021 build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C overflow-checks=on --cfg 'feature="default"' --cfg 'feature="ipv6"' -C metadata=13037c25982734ec -C extra-filename=-13037c25982734ec --out-dir /home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/einat-13037c25982734ec -C linker=x86_64-openwrt-linux-gnu-gcc -C strip=symbols -L dependency=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps --extern libbpf_cargo=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps/liblibbpf_cargo-fc7173ecf7072a22.rlib -L native=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/libbpf-sys-de20753a55c71e06/out -L native=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/deps -L native=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release -L native=/home/user/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/lib/rustlib/x86_64-unknown-linux-gnu/lib -L native=/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target/release/build/vsprintf-f6a1be3b8a629995/out` (exit status: 1)
warning: build failed, waiting for other jobs to finish...
error: failed to compile `einat v0.1.2 (/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3)`, intermediate artifacts can be found at `/home/user/works/openwrt/build_dir/target-x86_64_glibc_custom/einat-ebpf-0.1.3/target`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust build invocation shown in the issue and the package's build.rs, then review CONTRIBUTING.md for the repository's package-build conventions. Determine where linker flags are assembled and how a package can pass them to rustc; done means the einat build can link libintl without manually exporting environment variables.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.