libheif-sys icon indicating copy to clipboard operation
libheif-sys copied to clipboard

Static build fail on Macbook ARM (Mx)

Open neckaros opened this issue 11 months ago • 7 comments

I get the following error while trying to compile:

note: ld: warning: ignoring duplicate libraries: '-lm'
          ld: library 'stdc++' not found
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

my cargo.toml is as follow:

[package]
name = "rs-heic"
version = "0.1.0"
edition = "2021"

[dependencies]
libheif-sys = { version = "3.1.0", features = ["compile-libheif", "embedded-libheif-plugins"] }
image = "0.24"
anyhow = "1.0"

[build-dependencies]
cmake = "0.1.52"

I tried adding

[build]
rustflags = ["-C", "link-args=-lc++"]

to my cargo but to no effect

full error:

error: linking with `cc` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/arnaudjezequel/Library/pnpm:/opt/local/bin:/opt/local/sbin:/Users/arnaudjezequel/.cargo/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/ht/v4cz5tnj1gx8wm6g1m1gdpqh0000gn/T/rustc3G1eMN/symbols.o" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/rs_heic-86f20d7479005c3b.4x4fcgmia20ofvorzhao0y451.rcgu.o" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/rs_heic-86f20d7479005c3b.63mtfk9f5dqrtsybw2wxswpvi.rcgu.o" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/rs_heic-86f20d7479005c3b.86l6qn59hoysm2gazj2i0444w.rcgu.o" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/rs_heic-86f20d7479005c3b.94y32qqfb0gj0ftot8c1z87nt.rcgu.o" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/rs_heic-86f20d7479005c3b.e82wk8uj42or48xv5fgqnarqp.rcgu.o" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/rs_heic-86f20d7479005c3b.4vba6fmary5jryq4olkssr92w.rcgu.o" "-L" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps" "-L" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/build/libheif-sys-d1bf156a355cbd9d/out/libheif_build/lib" "-L" "/opt/local/lib" "-L" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/liblibheif_sys-959a5425d97e62c1.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/liblibc-737fc78a3962469c.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libimage-d34483b9b9043f6b.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libqoi-42ed7d177ccfa693.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libbytemuck-95ffda090626f8e9.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libpng-5bcc6841a33da945.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libbitflags-36d60268ceedfaf1.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libfdeflate-939c08109cb39829.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libexr-6cfcb219d8504c7b.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libzune_inflate-8ca94421dff491d6.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libbit_field-10c641f45e3a909f.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/liblebe-cef2b309b380b57e.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libhalf-fd033d33739ce710.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libsmallvec-94621f2eb80316e3.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libgif-9ec6654f7e00fe20.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libcolor_quant-4b0b1fd54822647b.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libbyteorder-f506f84707ac87c1.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libnum_traits-8a8f59273985953c.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libtiff-1cd4c6d9067edd6f.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libflate2-9d40ca100392f609.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libminiz_oxide-e23dcf8805972096.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libsimd_adler32-fed46eceddc57cda.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libcrc32fast-ae2e8f835aebb504.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libcfg_if-708624bee5970fc4.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libweezl-74e60a17e3ec834f.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libjpeg_decoder-1b3067f20aadcb73.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/librayon-6b720489c01971e6.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/librayon_core-aa89d1edd11e84d1.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libcrossbeam_deque-12b987f7566a0afe.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libcrossbeam_epoch-e8ef919f6c51950b.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libcrossbeam_utils-4e128ba09e4ab717.rlib" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libeither-b48377f2f81a5cae.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-4660195e40d1caa2.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-db24976b4a143f5b.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-753024f8b1329867.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-926dfdc3a6c0e753.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-43d582d3cac33899.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-fc73a57ad7ed2a0b.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-c2ed8b7ec4bfeb34.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-60d7c0705d969f46.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-18d33498f2e954c4.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-b39c946b13bf038c.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-ac55c803a24c5c25.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-ce7d16f103e5ca1c.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-59087b9a5642f6c7.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-4e2d55f7c361803f.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-d5410186db5469b8.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-49a09d1649b15de2.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-b5ebe01a91085ca1.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-855de1c067a46793.rlib" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-db7578c38859ed37.rlib" "-lc++" "-lstdc++" "-ldl" "-lpthread" "-lm" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/rs_heic-86f20d7479005c3b" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: warning: ignoring duplicate libraries: '-lm'
          ld: library 'stdc++' not found
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

warning: `rs-heic` (bin "rs-heic") generated 5 warnings
error: could not compile `rs-heic` (bin "rs-heic") due to 1 previous error; 5 warnings emitted

Caused by:
  process didn't exit successfully: `/Users/arnaudjezequel/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name rs_heic --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=193 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=86f20d7479005c3b -C extra-filename=-86f20d7479005c3b --out-dir /Users/arnaudjezequel/Developer/rs-heic/target/debug/deps -C incremental=/Users/arnaudjezequel/Developer/rs-heic/target/debug/incremental -L dependency=/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps --extern anyhow=/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libanyhow-97a225510ed999d8.rlib --extern image=/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/libimage-d34483b9b9043f6b.rlib --extern libheif_sys=/Users/arnaudjezequel/Developer/rs-heic/target/debug/deps/liblibheif_sys-959a5425d97e62c1.rlib -L native=/Users/arnaudjezequel/Developer/rs-heic/target/debug/build/libheif-sys-d1bf156a355cbd9d/out/libheif_build/lib -L native=/opt/local/lib` (exit status: 1)

neckaros avatar Jan 21 '25 11:01 neckaros

I'm afraid I can't reproduce this error - I don't have any Apple device.

Did you try to find this error in the Internet? May be something like this will help you.

Cykooz avatar Jan 21 '25 11:01 Cykooz

Thanks for taking the time to reply. Unfortunately it did not help. Working well on windows not sure what is blocking on Mac. Seems there is an hard dependency somewhere to stdc++ which is not supported on modern Macs

neckaros avatar Jan 24 '25 21:01 neckaros

When i look at the build output of the libheif-sys i find that stdc++ linked (build finish without issues):

(/Users/arnaud/Documents/dev/redseat-rust/target/debug/build/libheif-sys-a432f343eebbf632/output)

... [ 98%] Building C object gdk-pixbuf/CMakeFiles/pixbufloader-heif.dir/pixbufloader-heif.c.o [100%] Linking CXX shared module libpixbufloader-heif.so [100%] Built target pixbufloader-heif Install the project... -- Install configuration: "Debug" ... cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR cargo:rustc-link-search=native=/Users/arnaud/Documents/dev/redseat-rust/target/debug/build/libheif-sys-a432f343eebbf632/out/libheif_build/lib cargo:rustc-link-search=native=/opt/local/lib cargo:rustc-link-lib=static=heif cargo:rustc-link-lib=c++ cargo:rustc-link-lib=static=de265 cargo:rustc-link-lib=stdc++ cargo:rustc-link-lib=static=x265 cargo:rustc-link-lib=dl cargo:rustc-link-lib=static=aom ...

Not sure where it's comming from...

neckaros avatar Jan 25 '25 11:01 neckaros

I have some suspicions that the default build configuration of libheif builds not only library but additional things such as CLI tools and plugin for GTK that creates thumbnails.

I will try to find how to disable building these unnecessary things.

Cykooz avatar Jan 25 '25 11:01 Cykooz

Could you try to use libheif-sys from dev brach?

Cykooz avatar Jan 25 '25 20:01 Cykooz

Hey thanks!

So I tried: libheif-sys = { git = "https://github.com/Cykooz/libheif-sys", features = ["compile-libheif", "embedded-libheif-plugins"], branch = "dev"} and i still get the issue (each test i did cargo clean before cargo build) But I tried So i tried: libheif-sys = { git = "https://github.com/Cykooz/libheif-sys", features = ["compile-libheif"], branch = "dev"} and it compiled! (not with master branch version I verified)

Nice find with the example! Would it help if i forked your dev code dans tried removing plugins from the build rs to isolate a problematic one?

neckaros avatar Jan 26 '25 09:01 neckaros

Would it help if i forked your dev code dans tried removing plugins from the build rs to isolate a problematic one?

I think it will be useful if you try to find what plugin is responsible for the problem.

Cykooz avatar Feb 01 '25 20:02 Cykooz