Search code examples
rustbevy

Compiling bevy_dylib v0.5.0 error: linking with `cc` failed: exit status: 1


On Mac freshly upgraded to Monterey, I'm getting the following when attempting to cargo run a trivial Bevy program. I've reinstalled XCode CLTs like recommended here and other places. I've tried messing around with some of the cargo.yml with no success.

   Compiling bevy_dylib v0.5.0
error: linking with `cc` failed: exit status: 1
 note: "cc" "-Wl,-exported_symbols_list,/var/folders/rp/lky8r76j5v5dk0rqg_yzk35w0000gn/T/rustcDYBmaq/list" 
"-m64" "-arch" "x86_64" <......... many pages of warnings>
ld: warning: object file (/Users/BWStearns/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy-glsl-to-spirv-0.2.1/build/osx/libSPIRV-Tools-opt.glsltospirv.a(const_folding_rules.cpp.o)) was built for newer macOS version (10.13) than being linked (10.7)
<many more pages of warnings>
            "_CGDisplayCreateUUIDFromDisplayID", referenced from:
                _$LT$winit..platform_impl..platform..monitor..MonitorHandle$u20$as$u20$core..cmp..PartialEq$GT$::eq::h541b069daf520ec9 in libwinit-4f8b93ad49cc21f8.rlib(winit-4f8b93ad49cc21f8.winit.355ded65-cgu.6.rcgu.o)
                _$LT$winit..platform_impl..platform..monitor..MonitorHandle$u20$as$u20$core..cmp..Ord$GT$::cmp::h951d61f6bd1d7a5f in libwinit-4f8b93ad49cc21f8.rlib(winit-4f8b93ad49cc21f8.winit.355ded65-cgu.6.rcgu.o)
                winit::platform_impl::platform::monitor::MonitorHandle::ns_screen::h3207f8aed4eae22f in libwinit-4f8b93ad49cc21f8.rlib(winit-4f8b93ad49cc21f8.winit.355ded65-cgu.6.rcgu.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `bevy_dylib` due to previous error

The cargo.yml is like this:

[package]
name = "my_bevy_game"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.5.0", features = ["dynamic"] }

I just ran into this starting this week. I am pretty sure this exact code was compiling fine a couple weeks ago. Any help would be greatly appreciated.

main.rs looks like

use bevy::prelude::*;

struct Person;

struct Name(String);

fn add_people(mut commands: Commands) {
    commands.spawn().insert(Person).insert(Name("Elaina Proctor".to_string()));
    commands.spawn().insert(Person).insert(Name("Renzo Hume".to_string()));
    commands.spawn().insert(Person).insert(Name("Zayna Nieves".to_string()));
}

fn greet_people(query: Query<&Name, With<Person>>) {
    for name in query.iter() {
        println!("hello {}!", name.0);
    }
}

pub struct HelloPlugin;

impl Plugin for HelloPlugin {
    fn build(&self, app: &mut AppBuilder) {
        app.add_startup_system(add_people.system())
            .add_system(greet_people.system());
    }
}

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_plugin(HelloPlugin)
        .run();
}

Update:

Definitely something about the environment on my machine because on a different macbook it worked fine.


Solution

  • So I found a solution if you discover this issue and the code works on other machines. Uninstall rust with rustup self uninstall and then renistall with the standard script curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh and then you should be good.