Skip to content

Link error on MacOS arm64 #107

@lylythechosenone

Description

@lylythechosenone

Using this crate with qmetaobject on MacOS arm64, I get this strange error:

= note: ld: warning: ignoring file /Users/lysan/edit/target/debug/build/edit-ed5f1e2f905ca358/out/librust_cpp_generated.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
          Undefined symbols for architecture arm64:
            "___cpp_closure_17188711627517009258", referenced from:
                edit::main::h358ea517e810126f in edit-5673f38a0ffa045a.3yv251ocyfeukzqw.rcgu.o
          ld: symbol(s) not found for architecture arm64

Here's my build.rs (mostly copied from qmetaobject):

/* Copyright (C) 2018 Olivier Goffart <ogoffart@woboq.com>
   Copyright (C) 2023 Lysander Mealy <lysander.mealy@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

use semver::Version;

fn main() {
    let qt_include_path = std::env::var("DEP_QT_INCLUDE_PATH").unwrap();
    let qt_version = std::env::var("DEP_QT_VERSION")
        .unwrap()
        .parse::<Version>()
        .expect("Parsing Qt version failed");

    let mut config = cpp_build::Config::new();
    for f in std::env::var("DEP_QT_COMPILE_FLAGS")
        .unwrap()
        .split_terminator(';')
    {
        config.flag(f);
    }
    config.include(&qt_include_path).build("src/main.rs");

    for minor in 7..=15 {
        if qt_version >= Version::new(5, minor, 0) {
            println!("cargo:rustc-cfg=qt_{}_{}", 5, minor);
        }
    }
    let mut minor = 0;
    while qt_version >= Version::new(6, minor, 0) {
        println!("cargo:rustc-cfg=qt_{}_{}", 6, minor);
        minor += 1;
    }
}

and my actual code:

let mut component = QmlComponent::new(&engine);
component.load_url(
    QUrl::from(QString::from("ui/themes/Dark.qml")),
    CompilationMode::PreferSynchronous,
);
let object = component.create();
let variant = cpp!(unsafe [object as "QObject*"] -> QVariant as "QVariant" {
    return QVariant::fromValue(object);
});
engine.set_property("theme".into(), variant);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions