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

Linker undefined symbols - ld: Undefined symbols: std::__1::basic_string ... #1610

Closed
Ch4s3r opened this issue Jan 4, 2024 · 10 comments · Fixed by #1678
Closed

Linker undefined symbols - ld: Undefined symbols: std::__1::basic_string ... #1610

Ch4s3r opened this issue Jan 4, 2024 · 10 comments · Fixed by #1678
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working

Comments

@Ch4s3r
Copy link

Ch4s3r commented Jan 4, 2024

Describe the bug

Startup of application fails when adding the cargo dependency surrealdb with the SpeeDb backend enabled.
Generation of code is successful but running the application crashes right after starting.
Problem is the linker can't find some function std::basic_string, which is needed by surrealdb.
Creating a standalone cargo project with the same dependency and also a Tauri project, is working.

Steps to reproduce

  1. Add surrealdb = { version = "1.0.2", features = ["kv-speedb"] } as a depdencey into rust/Cargo.toml
  2. In the rust code rust/src/api/simple.rs add this import: use surrealdb::{engine::local::SpeeDb, sql::Thing};
  3. Generate and run the app on mac: flutter_rust_bridge_codegen generate && flutter run -d macos

Logs

❯ RUST_LOG=debug flutter run -d macos                                                                                                                                                                 
Launching lib/main.dart on macOS in debug mode...
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006001-001260A60A85801E }
{ platform:macOS, arch:x86_64, id:00006001-001260A60A85801E }
ld: Undefined symbols:
  std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::at(unsigned long) const, referenced from:
      rocksdb::Customizable::GetOptionName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) const in librust_lib.a[arm64][293](customizable.o)
  std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::find(char, unsigned long) const, referenced from:
      rocksdb::Cache::CreateFromString(rocksdb::ConfigOptions const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::shared_ptr<rocksdb::Cache>*) in librust_lib.a[arm64][144](cache.o)

Expected behavior

Starts up normally.

Generated binding code

No response

OS

MacOs

Version of flutter_rust_bridge_codegen

v2.0.0-dev.12

Flutter info

❯ flutter doctor -v
[✓] Flutter (Channel stable, 3.16.5, on macOS 14.2 23C64 darwin-arm64, locale
    en-AT)
    • Flutter version 3.16.5 on channel stable at
      /opt/homebrew/Caskroom/flutter/3.16.5/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 78666c8dc5 (2 weeks ago), 2023-12-19 16:14:14 -0800
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/lampe/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/lampe/Library/Android/sdk
    • Java binary at: /Users/lampe/Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C65
    ✗ Unable to get list of installed Simulator runtimes.
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Users/lampe/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.2)
    • IntelliJ at /Users/lampe/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.85.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.2 23C64 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 120.0.6099.199

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Version of clang++

15.0.0 (clang-1500.1.0.2.5)

Additional context

Notebook: Apple M1 (arm)

@Ch4s3r Ch4s3r added the bug Something isn't working label Jan 4, 2024
Copy link

welcome bot commented Jan 4, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 4, 2024

Hi, I guess this may be an issue of Cargokit, since flutter_rust_bridge core is just a code generator and is unaware of compilation mechanism. Thus, one way is to google about this, another way is to ask at cargokit.

Maybe related:

@fzyzcjy fzyzcjy changed the title Linker undefined symbols Linker undefined symbols - ld: Undefined symbols: std::__1::basic_string ... Jan 4, 2024
@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jan 4, 2024
@dxvid-pts
Copy link

See: irondash/cargokit#52

@Ch4s3r
Copy link
Author

Ch4s3r commented Jan 11, 2024

This irondash/cargokit#52 (comment) helped me with figuring out the solution.
Because I had the same issue when adding reqwest and the solution to adding -framework SystemConfiguration fixed it.
So I tried experimenting with the flags there and found some flags with -lc++ which sounded a bit like the error I had, as std::__1::basic_string was in the std lib which I guessed comes from -lc++. Which was correct in the end.

Had to change this line:

    'OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/librust_lib.a',
    'OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/librust_lib.a -lc++',

Not sure from which project the rust_builder comes from, but maybe it might make sense to add some flags per default?
Would this slow down overall building if not used?
Or maybe just mention this in the FAQ or README

@Ch4s3r
Copy link
Author

Ch4s3r commented Jan 11, 2024

ld: Undefined symbols:
  _SCDynamicStoreCopyProxies, referenced from:
      system_configuration::dynamic_store::SCDynamicStore::get_proxies::hca7a3e33ea42720a in librust_lib.a[arm64][156](system_configuration-59f513f20dd3f600.system_configuration.56b5e6df31efacc4-cgu.0.rcgu.o)

is solved by

 'OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/librust_lib.a -framework SystemConfiguration',

So looking at the referenced function e.g. system_configuration helps identifying what framework or linking argument is missing.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 12, 2024

Not sure from which project the rust_builder comes from,

From this template: https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_codegen/assets/integration_template
(And as you know, it is thin and uses cargokit under the hood)

but maybe it might make sense to add some flags per default?
Would this slow down overall building if not used?

IMHO linking more things will slow down things; but not sure whether the slowdown is visible or not.

Or maybe just mention this in the FAQ or README

Sure! Feel free to PR in e.g. https://cjycode.com/flutter_rust_bridge/manual/troubleshooting (click "edit the page" button at bottom of it). (Let's put it there firstly; I may consider moving that page to somewhere more visible later)

@MateusHBR
Copy link
Contributor

I had experienced some issues linking CPAL because it uses AudioToolbox.framework and this tips helped me.

Just added this framework to be compiled and everything worked.

inside rust_builder/ios/rust_builder.podspec
'OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/librust_lib.a -framework AudioToolbox',

@Ch4s3r
Copy link
Author

Ch4s3r commented Jan 19, 2024

Thank you @fzyzcjy for updating the troubleshooting guide, wanted to do it sometime, but you were faster 🙂

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 19, 2024

You are welcome! Since you did not reply for a week, I originally thought you do not have the interest to PR. Anyway, looking forward to your future usage and PRs!

Copy link
Contributor

github-actions bot commented Feb 2, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working
Projects
None yet
4 participants