0

I have some code in c# that I export to the dll with [UnmanagedCallersOnly(EntryPoint = "XXX")]:

public class Symbol {
   [UnmanagedCallersOnly(EntryPoint = "Console_Symbol_ReverseColors")]
   public static void ReverseColors(nint sym) {
       // do smth
   }
}

that I then import in my c++ code

extern "C" __declspec(dllimport) void Console_Symbol_ReverseColors(void*);

When I compile for x64 (dotnet publish -p:NativeLib=Shared -p:SelfContained=true -r win-x64 -c Release) it all works well, but when i use dotnet publish -p:NativeLib=Shared -p:SelfContained=true -r win-x86 -c Release and try to link with my c++ code I get undefined reference errors.

I decided to use dumpbin to see the symbols in the x64 and x86 .lib file and x64:

20 public symbols

      B3C __imp_Console_Symbol_ReverseColors

x86:

20 public symbols

      B9C __imp__Console_Symbol_ReverseColors@4

In this cropped out part of the result of the dumpbin command appear are numbers after the main name of the function, which explains why my compiler (both cl and VS x86 clang-cl tested) complains about not finding the correctly named one

error: Console.obj : error LNK2019: unresolved external symbol __imp__Console_Symbol_ReverseColors referenced in function "xxx"

Does anybody know why this is happening in x86 cross-compile and not in x64, and how to fix it/go around it to somehow make it work?

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.