Failing to bind to SecurityInterface framework


I have bindings to classes (SFCertificateView and SFChooseIdentityPanel) of the SecurityInterface framework that worked find with the dynamic registrar. With the static registrar I get the following errors:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_SFCertificateView", referenced from:
      objc-class-ref in registrar-dfbe63.o
  "_OBJC_CLASS_$_SFChooseIdentityPanel", referenced from:
      objc-class-ref in registrar-dfbe63.o
ld: symbol(s) not found for architecture x86_64
clang : error : linker command failed with exit code 1 (use -v to see invocation)

I can fix this by including said framework in the Native References section of the project, but this is less than ideal since it's including it in the App bundle. Beside not wanting to bundle macOS frameworks in my app, it also messes with my signing script.

Any ideas?


  • ChrisHamonsChrisHamons USXamarin Team Xamurai
    edited September 2017

    Did you add your bindings to a "real" binding project or are they just shoved in your main project?

    Do you have them marked with the correct p/invoke or did you mark them __Internal.

    Without an example, code snipped, or more information, it is not likely anyone here will be able to help you.

  • XavierFortinXavierFortin USMember ✭✭
    edited September 2017

    Hi Chris,

    To be honest I think I'm far from familiar on how it should be done. They are pretty much shoved in the main project.

    Could you point out to any documentation or example on how it should properly be done? I'd start with this.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    So while looking for a sample to link, I realized our XM binding project sample was dreadfully out of date. While I was updating it, I came across an almost identical error.

    I fixed it by updating my invocation of clang used to build the binary to the following:

    clang -arch x86_64 -dynamiclib -fobjc-arc -fobjc-link-runtime -std=gnu99 SimpleClass.m -current_version 1.0 -compatibility_version 1.0 -framework Cocoa -o SimpleClass.dylib

    I would check your invocation against what an Xcode project uses (or your setting on the Xcode project). Using a binding project or static registrar causes the linker to do compile time checking that requires your binary to be in good shape. Dynamic let's you get away with a lot.

    The sample needs review by QA but you can look at it here until it lands.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Also here is some documentation:

    Ignore the bit about it being in preview. That's out of date (I have a documentation PR to fix it out as well).

  • XavierFortinXavierFortin USMember ✭✭

    Once again, thanks a lot!

    I'll get into this right next Monday and get back to you on this.

  • XavierFortinXavierFortin USMember ✭✭

    Hi Chris,

    I think I'm in need of some more clarifications.

    I'm trying to bind to a macOS framework (SecurityInterface.framework). How we did it up to now was by adding interfaces corresponding to the wanted classes in and API.cs file and then running bmac on it to create bindings classes (.g.cs). As mentioned in my first message, if I do this now, I get "Undefined symbols" errors.

    I've looked into your sample. You're binding to your SimpleClass class to which you have the source code directly into the project (header and implementation file). This is where I get confused, what would I do here for a .framework bundle? I can't really pass a .m file to clang? I'm not familiar with clang, so I might be lacking some important knowledge.

    Here's the bmac command we're using:

    /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bmac --sourceonly=true --tmpdir=$DIR/Bindings --unified-full-profile "$DIR/API.cs" -s="$DIR/enums.cs"

    I haven't yet succeeded in the previous step so I might get a little ahead of myself here, but I've looked at the SimpleClass.g.cs file in the sample and the format looks quite similar to what I already had running bmac. Am I assuming to much in thinking this is unlikely to resolve my issue?

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Oh, the SecurityInterface.framework, like the system one. I assumed it was some wrapper of yours or the like.

    Bindings projects were not designed with the concept of binding system frameworks. If you want to bind system frameworks, the expected way forward is to rebuild Xamarin.Mac.dll with it.

    Thinking about it, I could see why the static registrar is getting confused in that use case.

    I can think of three possibilities:

    • Have you tried adding a --link_flags="-framework SecurityInterface"? That might convince clang to resolve the symbols from there.
    • Use dynamic registrar
    • Rebuild Xamarin.Mac.dll with your binding improvements (and preferably file a public Pull Request with them so we can add them to future releases).
Sign In or Register to comment.