Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find libgcc.a in the cargo-apk-temp-extra-link-libraries #265

Closed
XX opened this issue Apr 21, 2022 · 4 comments · Fixed by #270
Closed

Cannot find libgcc.a in the cargo-apk-temp-extra-link-libraries #265

XX opened this issue Apr 21, 2022 · 4 comments · Fixed by #270

Comments

@XX
Copy link

XX commented Apr 21, 2022

When I build my project I get the following error:

$ cargo +stable apk build --lib --release
...
error: linking with `/home/xx/data/soft/install/dev/android-sdk//ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang` failed: exit status: 1
  |
  = note: "/home/xx/data/soft/install/dev/android-sdk//ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android23-clang" "-Wl,--version-script=/tmp/rustcKqLSqE/list" "-Wl,--allow-multiple-definition" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.0.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.1.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.10.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.11.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.12.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.13.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.14.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.15.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.2.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.3.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.4.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.5.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.6.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.7.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.8.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.hyper.7cae4a2f-cgu.9.rcgu.o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/hyper-95924f4b03ae77dc.1deg1xatl4hh73xf.rcgu.o" "-Wl,--as-needed" "-L" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps" "-L" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/release/deps" "-L" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib" "-Wl,-Bstatic" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libwant-90bffe310ccdd736.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libtry_lock-49c1a8c27d650c32.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libhttparse-43bc91c8de8be723.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libh2-646d400caac27e35.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libindexmap-836c245633536b1e.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libhashbrown-d48da2a6da51e088.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libahash-dd7bc9d1fbe7a017.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libgetrandom-e7e30047b6cf70dc.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libserde-a27421b4fbff2741.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libtokio_util-bf3dc80ffda2825e.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libtower_service-5e952907dea32a51.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libtracing-41d05879928f0da6.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libtracing_core-b1e7db531ccd8b87.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/liblazy_static-5004ec1714570de3.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libhttp_body-f6d53f8587610ce5.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libfutures_util-40f05b51f17939c1.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libfutures_io-1dca58cd4be3dc3d.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libslab-b043bb27038293f9.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libfutures_channel-cf7f4dd421ebd6d9.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libfutures_sink-5cfebf1b8da0d13c.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libfutures_task-78029833d1d6f9eb.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libpin_utils-26c88e259c6606ae.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libfutures_core-157a96ab999cd40e.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libtokio-237255b767b76fad.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libsignal_hook_registry-1d281aa69a94dee3.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libnum_cpus-bcc2241b1839a5bb.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libsocket2-8bf05dd781a3b8a0.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libmemchr-ca05a9b549c99627.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libonce_cell-813845a98471372b.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libpin_project_lite-97ba71b9852be622.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libmio-fb58524ad597bf8f.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/liblog-8273d75c73b2dd80.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libvalue_bag-e48dbb66e54b4221.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libparking_lot-e518327c3134107c.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libparking_lot_core-0a404abe547d790a.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/liblibc-fc9224acad40da45.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libcfg_if-dc4161dbeb7c01db.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libsmallvec-b50ac0eea64adfde.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/liblock_api-a688cd9b7cbfc9dc.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libscopeguard-e9359c8bfe4454e8.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libhttp-2bee43c03b8f6c1a.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libitoa-2b6382093b5f14f5.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libbytes-b46936191725d156.rlib" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libfnv-a15fde5ca0930bb0.rlib" "-Wl,--start-group" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libstd-af8cca4ce4f6804f.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libpanic_unwind-d20b7629bade7b19.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libminiz_oxide-0e0429dadfd01176.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libadler-f1884c9b41122156.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libobject-e4d8140a90db47ce.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libmemchr-7409783eefd1e836.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libaddr2line-e5d6d51ed5bbf971.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libgimli-70667b4716457f81.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libstd_detect-0e975b57636672c8.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/librustc_demangle-e513a68fe4301435.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libhashbrown-82f9c426c72474a5.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_alloc-e69adea976218243.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libunwind-5d21e2a63fe6a0f1.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libcfg_if-a5e658c5749822f1.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/liblibc-cf442dcec02ecfaf.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/liballoc-0a2707a8771b9442.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_core-ed1c6adb8e36cabe.rlib" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libcore-669955cdd70efb76.rlib" "-Wl,--end-group" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libcompiler_builtins-86e41092bca9bdf8.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lgcc" "-ldl" "-lc" "-lm" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/xx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib" "-o" "/home/xx/data/noogen/projects/laplace/laplace_mobile/target/aarch64-linux-android/release/deps/libhyper-95924f4b03ae77dc.so" "-Wl,--gc-sections" "-shared" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs"
  = note: ld: error: unable to find library -lgcc
          clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `hyper` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
Error: Command `cargo rustc --target aarch64-linux-android --lib --release -- -L /home/xx/data/noogen/projects/laplace/laplace_mobile/target/cargo-apk-temp-extra-link-libraries` had a non-zero exit code.

But, when I copy the target/cargo-apk-temp-extra-link-libraries/libgcc.a file to the ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib folder, the project builds successfully.

@dvc94ch
Copy link
Contributor

dvc94ch commented Apr 21, 2022

so if you look at the linker args the /home/xx/data/noogen/projects/laplace/laplace_mobile/target/cargo-apk-temp-extra-link-libraries path is missing, but it is passed to cargo earlier. can you tell us what version of cargo you're using? if it's not the most recent stable try the most recent stable. If it is the most recent stable try an older version.

@XX
Copy link
Author

XX commented Apr 21, 2022

@dvc94ch

$ cargo +stable --version
cargo 1.59.0 (49d8809dc 2022-02-10)

I update Rust to the 1.60.0, but the error is still reproduced.

@MarijnS95
Copy link
Member

MarijnS95 commented Apr 21, 2022

This is a strange but known issue. hyper as intermediate crate builds a shared object on the side through crate-type = ["rlib", "cdylib"], and for some yet-unknown reason this -L flag is only applied to the final library of your project that is being built.

Our solution was to just get rid of hyper altogether (a longstanding goal which we were completing around the same time) but I'm not sure how to fix this immediately. Perhaps setting it through RUSTFLAGS instead of the rustc invocation might work.

MarijnS95 added a commit that referenced this issue May 11, 2022
Any flags passed directly to `cargo rustc` will only be passed _to the
final compiler invocation_.  However `cdylib` library targets in
transitive (dependency) crates will still be built (despite not being
used in the final binary, that's what `rlib`s are for), but our NDK r23
workaround flags will not reach these compiler invocations rendering
b912a6b ("cargo-apk: Work around missing libgcc on NDK r23 with linker
script (#189)") ineffective.

[The same page] that documents this discrepancy suggests to resort to
`RUSTFLAGS` if arguments are intended for all compiler invocations,
which is our intended use-case and unblocks builds with transitive
`cdylib` dependencies such as `hyper` in [#265].

[The same page]: https://doc.rust-lang.org/cargo/commands/cargo-rustc.html#description
[#265]: #265
@MarijnS95
Copy link
Member

@XX I hope to have fixed this in #270. Please let me know if/when you can test this, I'd like to make a patch release soon :)

MarijnS95 added a commit that referenced this issue May 12, 2022
Any flags passed directly to `cargo rustc` will only be passed _to the
final compiler invocation_.  However `cdylib` library targets in
transitive (dependency) crates will still be built (despite not being
used in the final binary, that's what `rlib`s are for), but our NDK r23
workaround flags will not reach these compiler invocations rendering
b912a6b ("cargo-apk: Work around missing libgcc on NDK r23 with linker
script (#189)") ineffective.

[The same page] that documents this discrepancy suggests to resort to
`RUSTFLAGS` if arguments are intended for all compiler invocations,
which is our intended use-case and unblocks builds with transitive
`cdylib` dependencies such as `hyper` in [#265].

[The same page]: https://doc.rust-lang.org/cargo/commands/cargo-rustc.html#description
[#265]: #265
MarijnS95 added a commit that referenced this issue May 12, 2022
…270)

Any flags passed directly to `cargo rustc` will only be passed _to the
final compiler invocation_.  However `cdylib` library targets in
transitive (dependency) crates will still be built (despite not being
used in the final binary, that's what `rlib`s are for), but our NDK r23
workaround flags will not reach these compiler invocations rendering
b912a6b ("cargo-apk: Work around missing libgcc on NDK r23 with linker
script (#189)") ineffective.

[The same page] that documents this discrepancy suggests to resort to
`RUSTFLAGS` if arguments are intended for all compiler invocations,
which is our intended use-case and unblocks builds with transitive
`cdylib` dependencies such as `hyper` in [#265].

[The same page]: https://doc.rust-lang.org/cargo/commands/cargo-rustc.html#description
[#265]: #265
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants