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

Cannot locate symbol "_ZSt15get_new_handlerv" #14

Closed
osoftware opened this issue Oct 3, 2020 · 56 comments
Closed

Cannot locate symbol "_ZSt15get_new_handlerv" #14

osoftware opened this issue Oct 3, 2020 · 56 comments

Comments

@osoftware
Copy link

I'm building a Flutter application that is using a Rust library (called using dart:ffi) for performance-critical parts. This generally works, until I try using oboe-rs inside my lib. To nail down the issue I left just this line of code:

        let mut builder = AudioStreamBuilder::default();

I compile the lib using cargo-ndk tool then put the output in jniLibs, like this:

cargo ndk --target armv7-linux-androideabi --platform 21 build && cp -f target/armv7-linux-androideabi/debug/libmylib.so android/app/src/main/jniLibs/armeabi-v7a/

Then, when I try to load this lib on the Dart side, I get this exception:

Failed to load dynamic library (dlopen failed: cannot locate symbol "_ZSt15get_new_handlerv" referenced by "<my lib>"...)

I tried using oboe-rs from creates.io and from source code, with and without compile-library feature, all result with the same error.

Please note that I have basically no experience in C++ - if this issue is somehow related to misconfiguration of my C++ stack, I don't even know what tools are involved exactly, except that I had to install cmake (I've got 3.16.3).

@chengchangwu
Copy link

Same here, but cannot locate another symbol.
If I run cargo ndk under ober-rs/oboe, a liboboe-ext.a is downloaded from github. But if I run cargo ndk under my own project which uses oboe-rs, no liboboe-ext.a is found under target directory. It seems that build script of oboe-sys is not executed.

@katyo
Copy link
Owner

katyo commented Oct 5, 2020

Hmm... Sounds quite strange. I cannot reproduce this issue.

Which version you use? I released 0.2.0 lately.
Are you tried enable 'compile-library' feature?
Can you share sample?

@katyo
Copy link
Owner

katyo commented Oct 5, 2020

@chengchangwu I fixed publishing on 'crates.io'.
So if you used published version this issue already fixed.
I hope.

@katyo
Copy link
Owner

katyo commented Oct 5, 2020

@osoftware, @chengchangwu
Can you test latest published version (0.2.1)?

@chengchangwu
Copy link

I've not tried 0.2.1, I'm using 0.2.0. It's strange that after I restructured my project trying to provide a sample to share, the issue disappeared. I can find liboboe-ext.a in target directory now. I did not use compile-library.

@osoftware
Copy link
Author

I tried 0.2.1 and still got the same missing symbol. What's interesting, it produces .so file of different sizes: when building from crates, I get 4.9MB, when pointing the dependency to a local repo clone (up to date), I get 4.8MB. Meanwhile, enabling or disabling compile-library feature doesn't affect the result.

Here's the entire lib.rs:

use oboe::{
    AudioInputStreamSync, AudioStream, AudioStreamBuilder, AudioStreamSync, Input, Mono,
    PerformanceMode, Status,
};
use pitch::{Pitch, PitchDetector, SAMPLE_RATE, SAMPLE_SIZE};

pub struct VoiceListener {
    // detector: PitchDetector,
    // stream: AudioStreamSync<Input, (f32, Mono)>,
    sample: [f32; SAMPLE_SIZE],
}

impl VoiceListener {
    pub fn new() -> Self {
        // let detector = PitchDetector::new();

        let mut sream = AudioStreamBuilder::default()
            // .set_exclusive()
            // .set_performance_mode(PerformanceMode::LowLatency)
            // .set_input()
            // .set_f32()
            // .set_mono()
            // .set_frames_per_callback(SAMPLE_SIZE as i32)
            // .set_sample_rate(SAMPLE_RATE as i32)
            // .open_stream()
            // .unwrap()
            ;
        Self {
            // detector,
            // stream,
            sample: [0.0; SAMPLE_SIZE],
        }
    }

    pub fn measure_sample(&mut self) -> Option<Pitch> {
        // match self.stream.read(&mut self.sample, 50_000) {
        //     Ok(_) => self.detector.measure(&self.sample),
        //     Err(_) => None,
        // }
        Some(Pitch {
            frequency: 21.37,
            clarity: 10.0,
        })
    }

    pub fn dispose(mut self) -> Status {
        // self.stream.close()
        Ok(())
    }
}

#[no_mangle]
pub extern "C" fn create_voice_listener() -> *mut VoiceListener {
    Box::into_raw(Box::new(VoiceListener::new()))
}

#[no_mangle]
pub unsafe extern "C" fn measure_sample(listener: *mut VoiceListener) -> *mut Pitch {
    if listener.is_null() {
        return Box::into_raw(Box::new(Pitch {
            frequency: f32::NAN,
            clarity: f32::NAN,
        }));
    }
    match (*listener).measure_sample() {
        Some(pitch) => Box::into_raw(Box::new(pitch)),
        None => Box::into_raw(Box::new(Pitch {
            frequency: f32::NAN,
            clarity: f32::NAN,
        })),
    }
}

#[no_mangle]
pub unsafe extern "C" fn dispose_voice_listener(listener: *mut VoiceListener) {
    if !listener.is_null() {
        let obj = Box::from_raw(listener);
        match obj.dispose() {
            _ => (),
        }
    }
}

And Cargo.toml:

[package]
name = "pitch-android"
version = "0.1.0"
authors = ["{o} Studio <*@*.*>"]
edition = "2018"

[lib]
crate-type = ["lib", "cdylib"]

[dependencies]
pitch = { path = "../pitch" }

[dependencies.oboe]
features = ["compile-library"]
version = "0.2.1"
# path = "../../../oboe-rs/oboe"

The other dependency (pitch) works fine when used alone.

Other interesting, maybe helpful thing: when I uncomment .open_strem().unwrap(), I get a different missing symbol: __gxx_personality_v0. As I read, this is something related to stack unwinding in libstdc++.

@katyo
Copy link
Owner

katyo commented Oct 5, 2020

@osoftware Looks quite strange. Which ndk version you use?

@osoftware
Copy link
Author

21.3.6528147

@katyo
Copy link
Owner

katyo commented Oct 6, 2020

I assume this related to linking with libc++.
Currently oboe-sys links with libc++_static (via build script).
We may try another variants to get work around it.

@katyo katyo closed this as completed Oct 6, 2020
@katyo katyo reopened this Oct 6, 2020
@katyo
Copy link
Owner

katyo commented Oct 6, 2020

I closed it mistakenly.

@chengchangwu
Copy link

I'm also using 21.3.6528147。It works now without compile-library. I can find the liboboe-ext.a downloaded under target. I do not need to compile any C++.

@katyo
Copy link
Owner

katyo commented Oct 8, 2020

@osoftware Seems your development environment misconfigured.
Can you test it without 'compile-library' feature?

@osoftware
Copy link
Author

I get the same errors without compile-library. For now, I use shared-link, copy apropriate libs to jniLibs and it works.

@katyo
Copy link
Owner

katyo commented Oct 9, 2020

@osoftware I still assume your build environment is not so clean.
I don't sure, but is seems linker uses wrong libc++ (In particular from host toolchain or from another ndk).

@osoftware
Copy link
Author

I replaces cargo ndk with this:

CC_armv7_linux_androideabi="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi16-clang" \
CXX_armv7_linux_androideabi="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi16-clang++" \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi16-clang" \
cargo build --target armv7-linux-androideabi

@katyo
Copy link
Owner

katyo commented Oct 10, 2020

Can you give me output of arm-linux-androideabi-readelf -d your-shared-lib.so
and arm-linux-androideabi-readelf --dyn-syms your-shared-lib.so | grep UND?
Of course, recompile without shared-link feature first.

@osoftware
Copy link
Author

@open-trade
Copy link

same problem with git clone https://github.com/katyo/oboe-rs

cargo ndk --platform 21 --target x86_64-linux-android test --release

  = note: /home/harveston/oboe-rs/target/x86_64-linux-android/release/deps/liboboe_sys-a2bc0772fcae7176.rlib(AudioStream.cpp.o):AudioStream.cpp:DW.ref.__gxx_personality_v0: error: undefined reference to '__gxx_personality_v0'
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

@open-trade
Copy link

Can we know which ndk version is used by oboe_sys prebuilt?

@katyo
Copy link
Owner

katyo commented Nov 1, 2020

@open-trade Current NDK bundle is used for build.
You can see NDK install command in workflow.

@Wicpar
Copy link

Wicpar commented Nov 29, 2020

I get something similar with "_ZTVN10__cxxabiv117__class_type_infoE" on 64 bit.
Has anyone managed to solve this ?
The weird part is that the symbol doesn't exist when i decompile the .so with ghydra.

Edit: 32 bit has same issue

Edit: Even the Pre-Built demo apk has the same error...

@SupernaviX
Copy link

I had a similar issue, but it was a quirk with my project. I was trying to link against another library which came with its own libc++_shared.so.

@Wicpar
Copy link

Wicpar commented Nov 29, 2020

@SupernaviX that's probably not it, it fails even with the given demo project...

The only reason I can find is that something changed with Android 11...

@katyo
Copy link
Owner

katyo commented Nov 30, 2020

@Wicpar Are you test apk from release page?

@Wicpar
Copy link

Wicpar commented Nov 30, 2020

@katyo Yes, i took the apk in the tag assets from the latest release.

@katyo
Copy link
Owner

katyo commented Nov 30, 2020

As an option we can try to link with c++_shared instead of c++_static.
But in that case libc++.so should be included in apk too.

@katyo
Copy link
Owner

katyo commented Nov 30, 2020

Seems I found working solution when I added c++_static directly to liboboe.
With this fix readelf already does not found the undefined symbols related to stdc++.

katyo added a commit that referenced this issue Nov 30, 2020
@Wicpar
Copy link

Wicpar commented Nov 30, 2020

Same error for me in the last build of #19

@Wicpar
Copy link

Wicpar commented Nov 30, 2020

@katyo can you send me the apk you built locally to see if it works ?

katyo added a commit that referenced this issue Nov 30, 2020
- Link c++_shared by default
@katyo
Copy link
Owner

katyo commented Nov 30, 2020

@Wicpar of course
https://mega.nz/file/ZGIHmQjJ#i27NZRxpj9eF_KtY3vGbuySGrvGYlWfvJsgu73EA5Qw (arm64 only)

Also I linked the c++_shared by default, you can test it too.
This should works fine but apk size is much bigger.

@Wicpar
Copy link

Wicpar commented Nov 30, 2020

@katyo the apk doesn't work on my phone:
java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/~~N4rvOMeqc5GGNaH46nmLeQ==/rust.oboe_demo-p9OF-3rAsdlBvOesD81fMA==/lib/arm64/liboboe_demo.so": dlopen failed: cannot locate symbol "__cxa_pure_virtual" referenced by "/data/app/~~N4rvOMeqc5GGNaH46nmLeQ==/rust.oboe_demo-p9OF-3rAsdlBvOesD81fMA==/lib/arm64/liboboe_demo.so"...

@open-trade
Copy link

open-trade commented Dec 1, 2020

cpal

Suggest you give up using cpal +oboe, I had solved link problem, but cpal hanged with initializing. Eventually, I used liboboe.a directly with my simple FFI wrapper, everything worked fine. Using these 3rd bindings took much more time. Check out my app, http://rustdesk.com

@Wicpar
Copy link

Wicpar commented Dec 1, 2020

@open-trade i have no choice but to use cpal, i need ios support as well as desktop. I think i will just bind directly to opensl-es and make a PR

@open-trade
Copy link

@Wicpar my desktop and ios still use cpal

@chengchangwu
Copy link

I've solved this issue before. But I've forgotten the details. Seems I have re-exported that C function in rust file so that it can be located by the dynamic loader.

@katyo
Copy link
Owner

katyo commented Jan 7, 2021

@Wicpar, @SupernaviX, @open-trade, @osoftware, @chengchangwu
Pls, help me to test PR #21

@SupernaviX
Copy link

Wow, I didn't know you could install crates from a branch! Pretty convenient.

@katyo when I tried installing the PR I got build errors. In cargo.toml I added

[target.'cfg(target_os = "android")'.dependencies]
oboe = { git = "https://github.com/katyo/oboe-rs", branch = "packaged-sources" }

And then when compiling oboe-sys I got the error

failed to run custom build command for `oboe-sys v0.3.0 (https://github.com/katyo/oboe-rs?branch=packaged-sources#ff90c6b2)`


Caused by:
  process didn't exit successfully: `C:\Codez\vvb\target\release\build\oboe-sys-80ec34c1feba8e2b\build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("i686-linux-android")
  OPT_LEVEL = Some("3")
  HOST = Some("x86_64-pc-windows-msvc")
  CXX_i686-linux-android = None
  CXX_i686_linux_android = None
  TARGET_CXX = None
  CXX = None
  CXXFLAGS_i686-linux-android = None
  CXXFLAGS_i686_linux_android = None
  TARGET_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  running: "clang++.exe" "--target=i686-linux-android" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=i686-linux-android" "-static" "-I" "oboe\\include" "-I" "oboe\\src" "-I" "oboe-ext\\include" "-I" "oboe-ext\\src" "-Wall" "-Wextra" "-std=c++14" "-Wall" "-Wextra-semi" "-Wshadow" "-Wshadow-field" "-fno-rtti" "-fno-exceptions" "-o" "C:\\Codez\\vvb\\target\\i686-linux-android\\release\\build\\oboe-sys-aa754ba71faa1400\\out\\library\\oboe\\src\\common/AudioSourceCaller.o" "-c" "oboe\\src\\common/AudioSourceCaller.cpp"
  running: "clang++.exe" "--target=i686-linux-android" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=i686-linux-android" "-static" "-I" "oboe\\include" "-I" "oboe\\src" "-I" "oboe-ext\\include" "-I" "oboe-ext\\src" "-Wall" "-Wextra" "-std=c++14" "-Wall" "-Wextra-semi" "-Wshadow" "-Wshadow-field" "-fno-rtti" "-fno-exceptions" "-o" "C:\\Codez\\vvb\\target\\i686-linux-android\\release\\build\\oboe-sys-aa754ba71faa1400\\out\\library\\oboe\\src\\aaudio/AAudioLoader.o" "-c" "oboe\\src\\aaudio/AAudioLoader.cpp"
  running: "clang++.exe" "--target=i686-linux-android" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=i686-linux-android" "-static" "-I" "oboe\\include" "-I" "oboe\\src" "-I" "oboe-ext\\include" "-I" "oboe-ext\\src" "-Wall" "-Wextra" "-std=c++14" "-Wall" "-Wextra-semi" "-Wshadow" "-Wshadow-field" "-fno-rtti" "-fno-exceptions" "-o" "C:\\Codez\\vvb\\target\\i686-linux-android\\release\\build\\oboe-sys-aa754ba71faa1400\\out\\library\\oboe\\src\\common/AudioStream.o" "-c" "oboe\\src\\common/AudioStream.cpp"
  running: "clang++.exe" "--target=i686-linux-android" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=i686-linux-android" "-static" "-I" "oboe\\include" "-I" "oboe\\src" "-I" "oboe-ext\\include" "-I" "oboe-ext\\src" "-Wall" "-Wextra" "-std=c++14" "-Wall" "-Wextra-semi" "-Wshadow" "-Wshadow-field" "-fno-rtti" "-fno-exceptions" "-o" "C:\\Codez\\vvb\\target\\i686-linux-android\\release\\build\\oboe-sys-aa754ba71faa1400\\out\\library\\oboe\\src\\aaudio/AudioStreamAAudio.o" "-c" "oboe\\src\\aaudio/AudioStreamAAudio.cpp"
  running: "clang++.exe" "--target=i686-linux-android" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=i686-linux-android" "-static" "-I" "oboe\\include" "-I" "oboe\\src" "-I" "oboe-ext\\include" "-I" "oboe-ext\\src" "-Wall" "-Wextra" "-std=c++14" "-Wall" "-Wextra-semi" "-Wshadow" "-Wshadow-field" "-fno-rtti" "-fno-exceptions" "-o" "C:\\Codez\\vvb\\target\\i686-linux-android\\release\\build\\oboe-sys-aa754ba71faa1400\\out\\library\\oboe\\src\\common/AudioStreamBuilder.o" "-c" "oboe\\src\\common/AudioStreamBuilder.cpp"
  running: "clang++.exe" "--target=i686-linux-android" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=i686-linux-android" "-static" "-I" "oboe\\include" "-I" "oboe\\src" "-I" "oboe-ext\\include" "-I" "oboe-ext\\src" "-Wall" "-Wextra" "-std=c++14" "-Wall" "-Wextra-semi" "-Wshadow" "-Wshadow-field" "-fno-rtti" "-fno-exceptions" "-o" "C:\\Codez\\vvb\\target\\i686-linux-android\\release\\build\\oboe-sys-aa754ba71faa1400\\out\\library\\oboe\\src\\common/DataConversionFlowGraph.o" "-c" "oboe\\src\\common/DataConversionFlowGraph.cpp"

  --- stderr


  error occurred: Failed to find tool. Is `clang++.exe` installed? (see https://github.com/alexcrichton/cc-rs#compile-time-requirements for help)

If it makes a difference, my project uses the rust-android-gradle plugin with prebuilt toolchains.

@katyo
Copy link
Owner

katyo commented Jan 8, 2021

@SupernaviX Have the master branch compiling with "compile-library" feature enabled?

Looks like rust-android-gradle plugin is outdated. I already fixed missing CXX_<target> env var by pr #26.
The oboe crate had workaround but I removed it because I tought that it already does not needed.

@SupernaviX
Copy link

@katyo the master branch doesn't compile when I enable that feature. The error is different (it's complaining that I don't have cmake, instead of complaining that I don't have clang++.exe), but it's still failing to build.

It looks like you're right, I'm using a rust-android-gradle version without your fix. The latest published version of rust-android-gradle (0.8.3) is from October 2019, but your PR is from Feb 2020. I couldn't figure out how to use the master version of rust-android-gradle on my machine, so I wasn't able to test the fix against that version.

Do you have advice on how to use the git version of rust-android-gradle in a project? I think I either need to figure out how to do that, or lock oboe to 0.2.1.

@katyo
Copy link
Owner

katyo commented Jan 9, 2021

@SupernaviX I added workaround back so you can test it now without upgrading gradle plugin.

@SupernaviX
Copy link

@katyo thanks, it works! No compilation issues, and I didn't have to muck with clang++ or cmake

@covercash2
Copy link
Contributor

covercash2 commented Jan 12, 2021

i'm also experiencing this issue.

i was getting the missing symbol _ZTVN10__cxxabiv117__class_type_infoE, which is what led me here.

i've switched to the "packaged-sources" branch and now i'm getting a similar UnsatisfiedLinkError when i compile with rust-android-gradle but now with symbol not found: __cxa_pure_virtual, which sounds like it could be my fault, but i'm a total n00b when it comes to C/C++ linker stuff.

also, rust-android-gradle is able to compile, but my CLI cargo build --release <target> is failing:

...
error occurred: Failed to find tool. Is `aarch64-linux-android-clang++` installed?

@katyo
Copy link
Owner

katyo commented Jan 12, 2021

@covercash2 You should set env var CXX_{triple} with c++ compiler corresponding to your target and android platform or simply build using cargo-ndk or rust android gradle plugin.

@covercash2
Copy link
Contributor

i'm still getting symbol not found: __cxa_pure_virtual with both rust-android-gradle and with cargo-ndk :/

@covercash2
Copy link
Contributor

covercash2 commented Jan 12, 2021

i added

#[no_mangle]
pub extern "C" fn __cxa_pure_virtual() {
    loop {}
}

and now the error is now: dlopen failed: cannot locate symbol "__gxx_personality_v0"

after some reading, it seems like i'm not linking the C++ stdlib, at least the error handling. i'm also getting oboe/include/oboe/Definitions.h:21:10: fatal error: 'cstdint' file not found with generate-bindings enabled.

katyo added a commit that referenced this issue Jan 14, 2021
- Link c++_shared by default
@katyo
Copy link
Owner

katyo commented Jan 14, 2021

@covercash2 Looks like attempt to link of code which compiled with both libstdc++ and libc++

@covercash2
Copy link
Contributor

sorry for the delay, i got busy all of a sudden.

i updated to the master branch and also tried 0.4 and i'm still getting symbol not found: __cxa_pure_virtual

@covercash2
Copy link
Contributor

just on a hunch i tried it on my phone and i didn't get the error. just on the emulator. i did include x86_64 as a compiler target, though. i didn't realize it would be an issue.

@katyo
Copy link
Owner

katyo commented Feb 26, 2021

I close this issue for now.
Feel free to reopen it if such problem occurs later.

@chriscoomber
Copy link

chriscoomber commented Sep 23, 2021

I was hitting the __cxa_pure_virtual issue, but only for debug mode. When I switched to always using release mode, the issue went away. Just something that people reading this might want to try. This isn't a great fix, but it's good enough for now. Edit: scratch that, it seems to be reoccurring still, semi-randomly. I'll report back if I can get anything more consistent.

@tGrothmannFluffy
Copy link

I am having the same issue right now.

I always either get missing symbol __gxx_personality_v0, missing symbol __cxa_pure_virtual, or Failed to load dynamic library 'libnative.so': dlopen failed: library "libc++_shared.so" not found (libnative would be my own)

See the issue I opened on flutter_rust_bridge. Maybe someone is able to see what the problem is in this repo I set up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants