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

Missing Symbols Despite SelfContained flag #2296

Closed
DrewRidley opened this issue Jun 3, 2023 · 4 comments
Closed

Missing Symbols Despite SelfContained flag #2296

DrewRidley opened this issue Jun 3, 2023 · 4 comments
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation question Further information is requested

Comments

@DrewRidley
Copy link

Hey all, hope everyone is doing well. I am currently trying to compile a very popular C# physics engine, bepu, and am trying to write bindings to rust with bindgen.

Unfortunately, I managed to get as far as some linker errors, but I am unsure as how to proceed as the documentation is not clear why the CoreLibs might not be in the final binary.

 "-nodefaultlibs"
  = note: Undefined symbols for architecture arm64:
            "_GlobalizationNative_ChangeCase", referenced from:
                _S_P_CoreLib_System_Globalization_TextInfo__IcuChangeCase in libbepuvy_sys-cde9651f76179dd8.rlib(AbominationInterop.o)
            "_GlobalizationNative_ChangeCaseInvariant", referenced from:
                _S_P_CoreLib_System_Globalization_TextInfo__IcuChangeCase in libbepuvy_sys-cde9651f76179dd8.rlib(AbominationInterop.o)
            "_GlobalizationNative_ChangeCaseTurkish", referenced from:
                _S_P_CoreLib_System_Globalization_TextInfo__IcuChangeCase in libbepuvy_sys-cde9651f76179dd8.rlib(AbominationInterop.o)
            "_GlobalizationNative_CloseSortHandle", referenced from:
                _S_P_CoreLib_Interop_Globalization__CloseSortHandle in libbepuvy_sys-cde9651f76179dd8.rlib(AbominationInterop.o)
            "_GlobalizationNative_CompareString", referenced from:
                _S_P_CoreLib_System_Globalization_CompareInfo__IcuCompareString in libbepuvy_sys-cde9651f76179dd8.rlib(AbominationInterop.o)
            "_GlobalizationNative_EnumCalendarInfo", referenced from:
                _S_P_CoreLib_Interop_Globalization__EnumCalendarInfo_0 in libbepuvy_sys-cde9651f76179dd8.rlib(AbominationInterop.o)

Thats just a snippet of the full output, but a lot of the C# core dll references seem to be totally missing from the output. This still occurs even if I use <SelfContained>true</SelfContained>.

I am using the .net 8 preview publicly available, and am currently on an arm based M1 mac.
Please do let me know if it is a lack of complete support for my platform.

Thank you.

@jkotas
Copy link
Member

jkotas commented Jun 3, 2023

Native AOT project moved to https://github.com/dotnet/runtime. Could you please open questions like this in dotnet/runtime repo next time.

When linking the static libraries, it is important to also include additional dependencies. Some documentation about it is at https://github.com/dotnet/samples/tree/main/core/nativeaot/NativeLibrary#building-static-libraries . The most reliable way to find the complete list of additional dependencies is by publishing a shared library with detailed verbosity (/v:d argument for dotnet publish) and looking at the linker command line. We invoke linker via clang, so look for a command line that looks like this: "clang" "obj/Release/net8.0/linux-x64/native/repro.o" -o "bin/Release/net8.0/linux-x64/native/repro .....

The GlobalizationNative_* symbols are defined in libSystem.Globalization.Native.a library, so make sure that you are passing that library to the linker.

dotnet/runtime#70277 tracks improving the static linking scenario. Resolving as duplicate of dotnet/runtime#70277 .

@jkotas jkotas closed this as completed Jun 3, 2023
@jkotas jkotas added question Further information is requested area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation labels Jun 3, 2023
@DrewRidley
Copy link
Author

DrewRidley commented Jun 3, 2023

Thank you so much for getting back to me! I have the full logs, but I am still a bit confused as I dont seem to have any libraries in my output folder besides the one being built. Do I have to manually publish each of these dlls with NativeAOT and link accordingly?

https://gist.github.com/DrewRidley/52657436ccb3a347b94240f19eafe9e9

this output leaves no mention of any specific static libraries or symbols as far as I am aware.

@jkotas
Copy link
Member

jkotas commented Jun 3, 2023

These additional dependencies are not dropped into the output folder. They are in the native AOT package and need to be referenced via a full path.

Here is the relevant command link from your log:

"clang" "obj/Release/net8.0/osx.13-arm64/native/AbominationInterop.o" -o "bin/Release/net8.0/osx.13-arm64/native/AbominationInterop.dylib" -exported_symbols_list "obj/Release/net8.0/osx.13-arm64/native/AbominationInterop.exports" /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/sdk/libbootstrapperdll.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/sdk/libRuntime.WorkstationGC.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/sdk/libeventpipe-disabled.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/sdk/libstdc++compat.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/framework/libSystem.Native.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/framework/libSystem.Globalization.Native.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/framework/libSystem.IO.Compression.Native.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/framework/libSystem.Net.Security.Native.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/framework/libSystem.Security.Cryptography.Native.Apple.a /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/framework/libSystem.Security.Cryptography.Native.OpenSsl.a -g -Wl,-rpath,'@executable_path' -ldl -lobjc -lswiftCore -lswiftFoundation -lz -licucore -L/usr/lib/swift -lm -dynamiclib -Wl,-u,_NativeAOT_StaticInitialization -framework CoreFoundation -framework CryptoKit -framework Foundation -framework Security -framework GSS

You should include all /Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/..../*.a libraries listed on this command line when linking your library.
/Users/drewridley/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0-preview.4.23259.5/

@DrewRidley
Copy link
Author

DrewRidley commented Jun 3, 2023

I found the files,
Thank you for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants