MrcSnm / D-Metal-Binding

Bindings for the D language to Apple's Metal Graphics API
Boost Software License 1.0
6 stars 2 forks source link

_objc_msgSend_stret is undefined #5

Closed LunaTheFoxgirl closed 8 months ago

LunaTheFoxgirl commented 8 months ago

When compiling the following small example, linking to SDL2 and d-metal-binding, a linker error is thrown that _objc_msgSend_stret is undefined.

import std.stdio;
import std.exception;
import bindbc.sdl;
import metal;
import objc.runtime;
import objc.meta;

void main() {

 // Init SDL2
 auto load = loadSDL();
 enforce(load != SDLSupport.noLibrary, "SDL2 not found!");
 SDL_Init(SDL_INIT_VIDEO);

 SDL_Window* window = SDL_CreateWindow("Metal Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_METAL | SDL_WINDOW_ALLOW_HIGHDPI);
 SDL_MetalView view = SDL_Metal_CreateView(window);
 CAMetalLayer layer = cast(CAMetalLayer)SDL_Metal_GetLayer(view);
 writeln(layer.drawableSize());

 writeln("Edit source/app.d to start your project.");
}

Relevant output from dub

ld: Undefined symbols:
  _objc_msgSend_stret, referenced from:
      CAMetalLayer::drawableSize() in libmetal.a[12](objc.metal_gen.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
MrcSnm commented 8 months ago
"lflags": [
        "-framework", "Foundation",
        "-framework", "AppKit", 
                "-framework", "Metal", 
        "-lObjC", 
        "-all_load"

Those are usually some of the required linker flags for using that.

@LunaTheFoxgirl I don't know if I really should put them under this lib, but yeah you could give me your thoughts

MrcSnm commented 8 months ago

Also, if you wish to contribute, do send me your small hello world project :) It would be cool having a hello world here

LunaTheFoxgirl commented 8 months ago
"lflags": [
      "-framework", "Foundation",
      "-framework", "AppKit", 
                "-framework", "Metal", 
      "-lObjC", 
      "-all_load"

Those are usually some of the required linker flags for using that.

@LunaTheFoxgirl I don't know if I really should put them under this lib, but yeah you could give me your thoughts

This still fails on my M3 Max macbook pro. According to someone on twitter, _objc_msgSend_stret is simply not a thing on ARM versions of macOS, and as such _objc_msgSend should be called instead.

MrcSnm commented 8 months ago

Okay I'll send the fix. I'll trust since I don't have an ARM to test

MrcSnm commented 8 months ago

@LunaTheFoxgirl Updated to use objc_msgSend instead on ARM and AArch64

LunaTheFoxgirl commented 8 months ago

That fixed it

MrcSnm commented 8 months ago

Commit b6f8d3ea3854a679f1893f93bbadc20ce0624b64 also fixed the problem about missing linker flags