question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linking of native static library fails and the resulting package is including the native reference

See original GitHub issue

Description

When binding a native library the library is not statically linked to the executable. When the this package is consumed by the MAUI project the library is still not linked in to the iOS app so when packaged into a .ipa file the library is still not linked in and Apple rejects the app because of a the library being dynamic linked and its not a framework.

When building and packing the reproduction project (libmds.a is in Git LFS) the file libmds.a is added to the StaticLinkingNotWorking.1.0.0.nupkg under lib -> net7.0-ios16.1 -> StaticLinkingNotWorking.resources -> libmds.a

What I expected was for it to be linked into the lib -> net7.0-ios16.1 -> StaticLinkingNotWorking.dll file as it was when using the Xamarin binding project.

But whatever I do to try to statically link libmds.a it seems like the project insists on making it dynamically linked and add libmds.a as it was before.

I hope this repository is the correct place to report this issue, if not please point me to the correct place.

I can consume the package and get a running application locally on a iOS device but this issue causes uploads to AppStore to fail. The exact fail is this one:

Asset validation failed (90171) Invalid bundle structure. The “testApp.app/libmds.a” binary file is not permitted. Your app cannot contain standalone executables or libraries, other than a valid CFBundleExecutable of supported bundles. For details, visit: https://developer.apple.com/documentation/bundleresources/placing_content_in_a_bundle

(I changed the name of the app to testApp)

Steps to Reproduce

  1. Create a iOS binding project
  2. Add native static library (.a) file
  3. Build the project
  4. pack the project

Expected: libmds.a statically linked into the StaticLinkingNotWorking.dll file

Actual libmds.a added to the StaticLinkingNotWorking.resources folder and not linked in to the dll file.

Link to public reproduction project repository

https://github.com/tentom/staticLinkingNotWorking

Version with bug

7.0.92

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No known workarounds found.

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created a month ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
drasticactionscommented, Aug 16, 2023

This should be transferred to http://github.com/xamarin/xamarin-macios, unless I’m missing some context this isn’t related to the MAUI UI project.

0reactions
rmarinhocommented, Aug 16, 2023

This issue was moved to xamarin/xamarin-macios#18751

Read more comments on GitHub >

github_iconTop Results From Across the Web

Linking of native static library fails and the resulting ...
When binding a native library the library is not statically linked to the executable. When the this package is consumed by the MAUI...
Read more >
Linking static native library to managed C++ project pulls ...
Normally, such reference (once it fails to resolve) gets redirected to managed definition (which is generated, as stated above), but in this ...
Read more >
Static vs. Dynamic Linking | Baeldung on Computer Science
Explore differences between static and dynamic linking. ... That's the case with references to external libraries. The linker resolves them ...
Read more >
linking native C++ static library causes weird behaviour ...
Hi, Kevin,. I am not sure I can explain clearer -- my C++/CLI code fails to link because linker finds certain symbols (e.g....
Read more >
C / C++ Rules
The linkstatic attribute has a different meaning if used on a cc_library() rule. For a C++ library, linkstatic=True indicates that only static linking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found