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)
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
cccrate withnative/hub/build.rscan be an answer. Just another possibility 👀Hopefully, this should have been fixed in 4.5.0, but because
gstreamer-rsis not a system library, I think you might need to include C headers manually from the.xcodeprojfile.I didn’t inspect deeper into this step, so please share your progress if you have anything new 😃
I was able to make
machineid-rswork in theenable-other-cratesbranch. I had to add a system header file to themacosfolder 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
slintworks 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
lipothings and manually copy-pastelibhub.afile.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:
gstreamerdependency to theCargo.tomluse gstreamer;tonative/src/lib.rsAlthough we could generate non-fat
libhub.alibrary by modify cargokit (related lipo command), but the generated non-fatlibhub.astill wouldn’t be called right.Related code(
lipocommand): https://github.com/irondash/cargokit/blob/7a5bba8eefbfe7e567f754477fd172e7a06b153f/build_tool/lib/src/build_pod.dart#L33-L40At least I can find what they have in common. They depend on external C code.
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?
Unfortunately, this problem still exists.
Oh I see, you were using macOS. I just thought like you were using Windows. That’s mysterious…
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
.afiles 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
./exampledirectory 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
.podspecchanges:OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/libhub.aOTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/libhub.a -framework CoreServicesAfter 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:I tried using
-force_load,-all_load,-l, but it seems to have little effect.However, I have made some new discoveries:
The
target/debug/libhub.afile that built by commandcargo build, when I use commandar -t target/debug/libhub.ato inspect it, I have got a lot of messages that.ofiles has been compiled in this.alib file, here are some of the rusult:build/macos/Build/Products/Debug/rust_in_flutter/libhub.a
The
build/macos/Build/Products/Debug/rust_in_flutter/libhub.afile that built by rust_in_flutter and cargo_kit when I run commandflutter run, when I use commandar -t build/macos/Build/Products/Debug/rust_in_flutter/libhub.ato inspect it, I have got these: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.