最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Why are [UnmanagedCallersOnly(EntryPoint = "XXX")] exported in .lib file as XXX@number, when using native

programmeradmin0浏览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?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论