ivmarkov / rust-esp32-std-demo

Rust on ESP32 STD demo app. A demo STD binary crate for the ESP32[XX] and ESP-IDF, which connects to WiFi, Ethernet, drives a small HTTP server and draws on a LED screen.
Apache License 2.0
785 stars 105 forks source link

Linker error when using `RwLock.try_write()`. #146

Closed cwoolum closed 10 months ago

cwoolum commented 1 year ago

Similar to #24 , I am unable to compile when using RwLock.try_write(). I am calling esp_idf_sys::link_patches(); at the beginning of main. I've also tried adding println!("cargo:rustc-link-lib=pthread"); to my build.rs file but it doesn't make any difference.

 = note: [ldproxy] Running ldproxy
          Error: Linker C:/rust-esp32-std-demo/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch5-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc.exe failed: exit code: 1
          STDERR OUTPUT:
          c:/rust-esp32-std-demo/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch5-8.4.0/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\rust-esp32-std-demo\target\riscv32imc-esp-espidf\debug\deps\rust_esp32_std_demo-3f3c9170e2994b31.5c60wc8a7mwgqdr7.rcgu.o: in function `std::sync::rwlock::RwLock<T>::try_write':
          C:\Users\slick\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\unix\locks/pthread_rwlock.rs:164: undefined reference to `pthread_rwlock_trywrlock'
          collect2.exe: error: ld returned 1 exit status

          Stack backtrace:
             0: <unknown>
             1: <unknown>
             2: <unknown>
             3: <unknown>
             4: <unknown>
             5: <unknown>
             6: <unknown>
             7: <unknown>
             8: <unknown>
             9: BaseThreadInitThunk
            10: RtlUserThreadStart

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
ivmarkov commented 1 year ago

24 is specific for ESP IDF V4.3 only.

I suppose you are using V4.4 or even V5.0, so what you experience is different: ESP IDF does not seem to have pthread_rwlock_trywrlock implemented actually.

I guess if you avoid RWLock::try*, you'll not get these linker errors.