qaul.net icon indicating copy to clipboard operation
qaul.net copied to clipboard

iOS Linking error of Rust library in Flutter

Open MathJud opened this issue 3 years ago • 1 comments
trafficstars

Linking errors when running flutter run --verbose to run for iOS. The error occurs when Xcode tries to link the liblibqaul.a rust library. We tried the process without linking the library and everything was working fine.

/Users/brenodt/Library/Developer/Xcode/DerivedData/Runner-cxajtliqusxmskgmwpvlfdoekhps/Build/Intermediates.noindex/Runner.build/Debug-iphoneos/R
                  unner.build/Objects-normal/arm64/Runner_dependency_info.dat -o
                  /Volumes/brenodt/dev/qaul/qaul.net/qaul_ui/build/ios/Debug-iphoneos/Runner.app/Runner
              Undefined symbols for architecture arm64:
                "_SCDynamicStoreCreateRunLoopSource", referenced from:
                    system_configuration::dynamic_store::SCDynamicStore::create_run_loop_source::h348dbd25b938ed1a in
                    liblibqaul.a(system_configuration-426e3ed9b2df0aa7.system_configuration.26819103-cgu.3.rcgu.o)
                "_SCDynamicStoreCopyProxies", referenced from:
                    system_configuration::dynamic_store::SCDynamicStore::get_proxies::h8dd4188249cfc649 in
                    liblibqaul.a(system_configuration-426e3ed9b2df0aa7.system_configuration.26819103-cgu.3.rcgu.o)
                "_kSCDynamicStoreUseSessionKeys", referenced from:
                    system_configuration::dynamic_store::SCDynamicStoreBuilder$LT$T$GT$::build::h44dd5b3415e2ce3d in
                    liblibqaul.a(if_watch-3ac1f676709ce8da.if_watch.6307e884-cgu.9.rcgu.o)
                "_SCDynamicStoreCreateWithOptions", referenced from:
                    system_configuration::dynamic_store::SCDynamicStore::create::h2e61528deefe7dc7 in
                    liblibqaul.a(system_configuration-426e3ed9b2df0aa7.system_configuration.26819103-cgu.3.rcgu.o)
                "_SCDynamicStoreSetNotificationKeys", referenced from:
                    if_watch::apple::background_task::hb1e83e74825b355f in liblibqaul.a(if_watch-3ac1f676709ce8da.if_watch.6307e884-cgu.4.rcgu.o)
              ld: symbol(s) not found for architecture arm64
              clang: error: linker command failed with exit code 1 (use -v to see invocation)
          
          
              Result bundle written to path:
               /var/folders/kp/9szxq_hj3m7dl5f6v0bkbgq00000gn/T/flutter_tools.p9eaPW/flutter_ios_build_temp_dirhnqGqv/temporary_xcresult_bundle
          
          
[ +152 ms] Could not build the precompiled application for the device.
[   +4 ms] Error (Xcode): Undefined symbol: _SCDynamicStoreCreateRunLoopSource
          
[        ] Error (Xcode): Undefined symbol: _SCDynamicStoreCopyProxies
          
[        ] Error (Xcode): Undefined symbol: _kSCDynamicStoreUseSessionKeys
          
[        ] Error (Xcode): Undefined symbol: _SCDynamicStoreCreateWithOptions
          
[        ] Error (Xcode): Undefined symbol: _SCDynamicStoreSetNotificationKeys
          
[        ] Error launching application on Breno’s iPhone.
[   +1 ms] "flutter run" took 26,069ms.
[   +1 ms] 
          #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
          #1      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:699:9)
          <asynchronous suspension>
          #2      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1183:27)
          <asynchronous suspension>
          #3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #4      CommandRunner.runCommand (package:args/command_runner.dart:209:13)
          <asynchronous suspension>
          #5      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
          <asynchronous suspension>
          #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
          <asynchronous suspension>
          #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
          <asynchronous suspension>
          #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #10     main (package:flutter_tools/executable.dart:94:3)
          <asynchronous suspension>

MathJud avatar Sep 01 '22 19:09 MathJud

Missing Symbols

Modules that include problematic crates

if-watch crate

  • libp2p-mdns (if-watch 1.1.1)
  • libp2p-tcp (optionally)

system-configuration

MathJud avatar Oct 06 '22 12:10 MathJud

The linking errors are coming from the if-watch crate and system-configuration crate which is a dependeny of the if-watch crate.

The if-watch crate is a dependency of libp2p-mdns and libp2p-tcp https://github.com/mxinden/if-watch

if-watch linking errors:

"_kSCDynamicStoreUseSessionKeys", referenced from:
system_configuration::dynamic_store::SCDynamicStoreBuilder$LT$T$GT$::build::h44dd5b3415e2ce3d in
liblibqaul.a(if_watch-3ac1f676709ce8da.if_watch.6307e884-cgu.9.rcgu.o)
"_SCDynamicStoreSetNotificationKeys", referenced from:
if_watch::apple::background_task::hb1e83e74825b355f in liblibqaul.a(if_watch-3ac1f676709ce8da.if_watch.6307e884-cgu.4.rcgu.o)

Dependency tree of if-watch & system-configuration:

system-configuration v0.5.0
└── if-watch v2.0.0
    ├── libp2p-mdns v0.41.0
    │   └── libp2p v0.49.0
    │       ├── libqaul v2.0.0-beta.9 (/Users/foton/src/meshnet/qaul-libp2p_store/rust/libqaul)
    │       ├── qaul_info v0.1.0 (/Users/foton/src/meshnet/qaul-libp2p_store/rust/libp2p_modules/qaul_info)
    │       │   └── libqaul v2.0.0-beta.9 (/Users/foton/src/meshnet/qaul-libp2p_store/rust/libqaul)
    │       └── qaul_messaging v0.1.0 (/Users/foton/src/meshnet/qaul-libp2p_store/rust/libp2p_modules/qaul_messaging)
    │           └── libqaul v2.0.0-beta.9 (/Users/foton/src/meshnet/qaul-libp2p_store/rust/libqaul)
    └── libp2p-tcp v0.37.0
        └── libp2p v0.49.0 (*)

MathJud avatar Nov 13 '22 20:11 MathJud

File a bug report to if-watch crate. https://github.com/mxinden/if-watch/issues/29

MathJud avatar Nov 22 '22 11:11 MathJud

libqaul can be linked via Xcode in the following sample project when running Product > Archive from the Xcode Menu: https://github.com/MathJud/if-watch-ios/tree/link-libqaul

It still failes linking via any other build path (trying to click run in Xcode, build it from CLI, etc.).

It also still failes while trying to build/link it for the qaul app.

This means there are specific build settings that must be match in order to build it successfully.

MathJud avatar Dec 02 '22 09:12 MathJud

The iOS version is now available for public testing on Testflight https://testflight.apple.com/join/Opmxb2Ym

The linking error got fixed by adding the SystemConfiguration.framework to the linking step.

fixed by #504

MathJud avatar Dec 17 '22 12:12 MathJud