rinf: Build error with `flutter run`, but `cargo build` succeeds

Environment: macOS(Apple Silicon)

I have referenced the rust_in_flutter to my project, when I referencing the crate gstreamer or slint(just import the dependencies without anything, just like use gstreamer or use slint only), I encountered a compilation error after command flutter run:

 Undefined symbols for architecture arm64:

......

  "_gst_value_is_fixed", referenced from:
      _$LT$glib..value..Value$u20$as$u20$gstreamer..value..GstValueExt$GT$::is_fixed::h823c60aabddfbe8f in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.15.rcgu.o)
  "_gst_value_is_subset", referenced from:
      _$LT$glib..value..Value$u20$as$u20$gstreamer..value..GstValueExt$GT$::is_subset::hf7a9bde6fcc536af in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.15.rcgu.o)
  "_gst_value_list_append_and_take_value", referenced from:
      gstreamer::value::List::append_value::he03d6a36e2e564b2 in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.5.rcgu.o)
  "_gst_value_list_get_type", referenced from:
      _$LT$gstreamer..value..List$u20$as$u20$glib..types..StaticType$GT$::static_type::hdbbfb74f464ccb2a in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.5.rcgu.o)
  "_gst_value_serialize", referenced from:
      _$LT$glib..value..Value$u20$as$u20$gstreamer..value..GstValueExt$GT$::serialize::hbab20b6f4262a66b in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.15.rcgu.o)
  "_gst_value_subtract", referenced from:
      _$LT$glib..value..Value$u20$as$u20$gstreamer..value..GstValueExt$GT$::subtract::h3f9b69692b700b18 in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.15.rcgu.o)
  "_gst_value_union", referenced from:
      _$LT$glib..value..Value$u20$as$u20$gstreamer..value..GstValueExt$GT$::union::h2f0b2cb330fa73ba in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.15.rcgu.o)
  "_gst_version", referenced from:
      gstreamer::auto::functions::version::hd679fd4c79d0ecce in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.10.rcgu.o)
  "_gst_version_string", referenced from:
      gstreamer::auto::functions::version_string::hfad9ad3288d2432c in libhub.a(gstreamer-b69ba5941324da5c.gstreamer.d8b50d9cbf89a4f6-cgu.10.rcgu.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')

But the strange thing is that when I use cargo build to bypass rust_in_flutter, there is no error reported.

ps: The crate package gstreamer and slint both support macOS of apple silicon version.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 29 (29 by maintainers)

Most upvoted comments

Closing this assuming that it has been solved with recent updates, but please continue the conversation if anyone confronts this issue again 😃

Thank for you resolved the deeply hidden bug.

Your expertise and dedication in finding and fixing this bug have been greatly appreciated.

Or, perhaps using cc crate with native/hub/build.rs can be an answer. Just another possibility 👀

Hopefully, this should have been fixed in 4.5.0, but because gstreamer-rs is not a system library, I think you might need to include C headers manually from the .xcodeproj file.

image image

I didn’t inspect deeper into this step, so please share your progress if you have anything new 😃

I was able to make machineid-rs work in the enable-other-crates branch. I had to add a system header file to the macos folder of RIF. However, this cannot be a general solution because users need to be able to modify their own project, not RIF.

I thought about asking users to create their own Flutter FFI plugin in the docs, but that would be too much when simply trying to add header files to the binary.

At least slint works well 😃

https://github.com/cunarist/rust-in-flutter/issues/110#issuecomment-1691346024

It feels like this issue might be somehow related to this one, though I’m not sure. Because it also had to to lipo things and manually copy-paste libhub.a file.

At least I can find what they have in common. They depend on external C code.

  • Slint: skia, openGL
  • Gstreamer: C Gstreamer

The fact that they are not pure Rust crates might be related to this error. If we solve this problem, any other crates that depend on C code will be able to work properly as well.

Do you mind sharing your project’s code so that we can examine it together?

Great, maybe it is a important discovery that slint and gstreamer are non-purely rust crate.

I haven’t built a complex project yet, but in my experience, minimal method to reproduce the bug just only need:

  1. Add gstreamer dependency to the Cargo.toml
  2. Add use gstreamer; to native/src/lib.rs

Hmm, I have a feeling that we will need to make PRs at cargokit repository directly.

Although we could generate non-fat libhub.a library by modify cargokit (related lipo command), but the generated non-fat libhub.a still wouldn’t be called right.

Related code(lipo command): https://github.com/irondash/cargokit/blob/7a5bba8eefbfe7e567f754477fd172e7a06b153f/build_tool/lib/src/build_pod.dart#L33-L40

At least I can find what they have in common. They depend on external C code.

  • Slint: skia, openGL
  • Gstreamer: C Gstreamer

The fact that they are not pure Rust crates might be related to this error. If we solve this problem, any other crates that depend on C code will be able to work properly as well.

Do you mind sharing your project’s code so that we can examine it together?

By the way, does this problem persist? @bookshiyi

Unfortunately, this problem still exists.

Oh I see, you were using macOS. I just thought like you were using Windows. That’s mysterious…

This is a really valuable inspection! Though we don’t know what the problem is, we now know things that are NOT problems.

In addition, may I ask you to check if you are able to run the example Rust-In-Flutter app, located at ./example directory of this repository? I would like to do this myself, but I don’t have a M1 mac 👀.

This repository’s example works very well on apple silicon macOS. It is a beautiful work!

And I have tried to add some common packages without any problems. At present, I only found that when gstreamer or slint are added to my project, the correct .a files cannot be generated.

btw: I feel like we are getting closer to the truth too ,hahaha

This is a really valuable inspection! Though we don’t know what the problem is, we now know things that are NOT problems.

In addition, may I ask you to check if you are able to run the example Rust-In-Flutter app, located at ./example directory of this repository? I would like to do this myself, but I don’t have a M1 mac 👀.

@temeddix I’d like to provide some feedback:

I followed your advice, viewed super_native_extensions’s PR mentioned .podspec changes: OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/libhub.a OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/libhub.a -framework CoreServices

After command flutter run -v, the libhub.a file has been generated and it’s file path is correct.

This is some log of flutter run -v:

export OTHER_LDFLAGS\=\ -force_load\  /Users/USERNAME/repos/MYPROJECT/build/macos/Build/Products/Debug/rust_in_flutter/libhub.a

I tried using -force_load, -all_load, -l, but it seems to have little effect.


However, I have made some new discoveries:

  • target/debug/libhub.a

The target/debug/libhub.a file that built by command cargo build, when I use command ar -t target/debug/libhub.a to inspect it, I have got a lot of messages that .o files has been compiled in this .a lib file, here are some of the rusult:

once_cell-11185762ce73204a.once_cell.6731a559064eefbc-cgu.9.rcgu.o
bitflags-3f6b34c3afc19730.bitflags.ae1711ba5b25353a-cgu.0.rcgu.o
bitflags-3f6b34c3afc19730.bitflags.ae1711ba5b25353a-cgu.1.rcgu.o
bitflags-3f6b34c3afc19730.bitflags.ae1711ba5b25353a-cgu.2.rcgu.o
bitflags-3f6b34c3afc19730.bitflags.ae1711ba5b25353a-cgu.3.rcgu.o
bitflags-3f6b34c3afc19730.bitflags.ae1711ba5b25353a-cgu.4.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.0.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.1.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.10.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.11.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.12.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.2.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.3.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.4.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.5.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.6.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.7.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.8.rcgu.o
gstreamer_sys-cc6e64f60f76625c.gstreamer_sys.4b52fb123b01391e-cgu.9.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.0.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.1.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.10.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.11.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.2.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.3.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.4.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.5.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.6.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.7.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.8.rcgu.o
gobject_sys-a90e106e7eaef946.gobject_sys.4fd6e84bc28f226d-cgu.9.rcgu.o
glib_sys-fc580655124209bb.glib_sys.7d265415d2c044a9-cgu.0.rcgu.o
  • build/macos/Build/Products/Debug/rust_in_flutter/libhub.a

    The build/macos/Build/Products/Debug/rust_in_flutter/libhub.a file that built by rust_in_flutter and cargo_kit when I run command flutter run, when I use command ar -t build/macos/Build/Products/Debug/rust_in_flutter/libhub.a to inspect it, I have got these:

    ar: build/macos/Build/Products/Debug/rust_in_flutter/libhub.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
    ar: build/macos/Build/Products/Debug/rust_in_flutter/libhub.a: Inappropriate file type or format
    

Hi @temeddix , thanks.

Thank you for helping me identify the approach to troubleshoot the issue.

Even though I am a beginner in Rust, I really enjoy Rust and have a strong desire to contribute code to the open-source world.

I will try to fix this bug.