Brendonovich / swift-rs

Call Swift functions from Rust with ease!
Apache License 2.0
246 stars 28 forks source link

Undefined symbols for architecture arm64 on M1 #24

Closed Runeii closed 1 year ago

Runeii commented 1 year ago

Hi there,

I've set up a minimal reproduction of SwiftRS here: https://github.com/Runeii/rust-music-stats/tree/swift-rs

When I attempt to run main.rs I get the following error:

 *  Executing task: cargo run --package rust-music-stats --bin rust-music-stats 

   Compiling swift-rs v0.3.0 (https://github.com/Brendonovich/swift-rs?branch=master#09dae1fb)
   Compiling rust-music-stats v0.1.0 (/Users/andrew/repos/personal/rust-music-stats)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-arch" "arm64" "/var/folders/mn/j85983tj78n01_jgd5j8pxvh0000gn/T/rustc7F3NqS/symbols.o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec.1ms7ohmqftfn6q4w.rcgu.o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec.21hw1uwcq11n6ih0.rcgu.o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec.27gciweei5abzqm1.rcgu.o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec.2erbe4l2hmj5dh6r.rcgu.o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec.2hfu118oifftsf5h.rcgu.o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec.359raxiynlvfjxm8.rcgu.o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec.3y28qvj39b07q36f.rcgu.o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec.2uf1pkjg9hn4c8hp.rcgu.o" "-L" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps" "-L" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-16f2b65e77054c42.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-fd1704e37560507f.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-94f4da5460b31483.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-dd7958cec764aa42.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-17c11a45ade40adb.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-161277c6ccddcf93.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-9f3e69e85a9935a9.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-6f6f52105e0f6e24.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-56005cba759bfcab.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-8c2b5041146b4db9.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-649829904d7d66f8.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-c7b5f570b5a640c9.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-283e8c970a6afa53.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-2bdb7200e04f5706.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-071dd441119cfdb1.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-c73a2abddc2b801e.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-8174475fb0bfe96a.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-33fcb3a02520939a.rlib" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-50dfeec641ff2e68.rlib" "-lSystem" "-lc" "-lm" "-L" "/Users/andrew/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/andrew/repos/personal/rust-music-stats/target/debug/deps/rust_music_stats-f4d823cb689579ec" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: Undefined symbols for architecture arm64:
            "_square_number", referenced from:
                rust_music_stats::main::ha48bad41e6a71413 in rust_music_stats-f4d823cb689579ec.27gciweei5abzqm1.rcgu.o
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `rust-music-stats` due to previous error

 *  The terminal process "cargo 'run', '--package', 'rust-music-stats', '--bin', 'rust-music-stats'" terminated with exit code: 101. 
 *  Terminal will be reused by tasks, press any key to close it. 

For reference, Xcode builds without error.

I'm sure this is something simple that I'm doing wrong, but have tried to follow the setup instructions fairly closely. Does this typically run fine on M1/Ventura 13.0.1 machines?

Thanks

Runeii commented 1 year ago

I think I've spotted what I'm doing wrong, will follow up once I've confirmed it.

Runeii commented 1 year ago

There were a few issues here, listing them for anyone who might have similar issues. I'll leave my (fixed) minimal example on the link above for anyone who needs it.

Hope that helps

billyjacoby commented 1 year ago

I think I'm having this same issue but it looks like your repo is gone or private, could you share the relevant snippets here? @Runeii

tleyden commented 6 months ago

@billyjacoby I hit that error because I forgot to put the src/build.rs file into the project (which invokes swift_rs::SwiftLinker). I didn't need to add it to my cargo.toml file however.

Here's an example repo that has the same setup I'm using: https://github.com/LeviticusNelson/apple-vision-rs