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

Link error on MacOS arm64 #107

Open
lylythechosenone opened this issue Aug 7, 2023 · 3 comments
Open

Link error on MacOS arm64 #107

lylythechosenone opened this issue Aug 7, 2023 · 3 comments

Comments

@lylythechosenone
Copy link

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);
@ogoffart
Copy link
Collaborator

I cannot explain this bug looking at this code.
The ___cpp_closure_17188711627517009258 is probably the symbol created for your cpp! macro. It should be present in the generated .cpp file, could you check that?

@lylythechosenone
Copy link
Author

I think the important part here is not the "Undefined symbols..." but the "ignoring file..."

The symbols are present in the file, the file is just ignored.

@ogoffart
Copy link
Collaborator

I've never seen this message before.
If I search for this message I found rust-lang/cc-rs#680

Let me know if you find the solution and if something should be changed in the crate.

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

2 participants