Skip to content

LNK2038 mismatch detected in NativeAOT #85517

Closed

Description

@AhmedZero

Description

I build the C# ObjectArx library using NativeAOT for Cad programs like C++, but the library needs two export APIs "ACRXEntryPoint" and "acrxGetApiVersion".

Reproduction Steps

in c++ uses

#if !defined(_WIN64) && !defined (_AC64)
#pragma comment(linker, "/export:_acrxGetApiVersion,PRIVATE")
#else
#pragma comment(linker, "/export:acrxGetApiVersion,PRIVATE")
#endif

I want to make it like C++ in C#

  [DllImport("rxapi", EntryPoint = "acrxGetApiVersionImpl", CallingConvention = CallingConvention.Cdecl)]
        private static extern ulong acrxGetApiVersionImpl();
        [UnmanagedCallersOnly(EntryPoint = "acrxGetApiVersion")]
        public static ulong acrxGetApiVersion()
        {
            return acrxGetApiVersionImpl();
        }

Expected behavior

it should be build successfully.

Actual behavior

rxapi.lib(libinit.obj) : warning LNK4099: PDB '' was not found with 'rxapi.lib(libinit.obj)' or at ''; linking object as if no debug info [N:\My_Projects\asdkmgPoly\asdkmgPoly\asdkmgPoly.csproj]
msvcprt.lib(nothrow.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in Runtime.WorkstationGC.lib(thread.cpp.obj) [N:\My_Projects\asdkmg
Poly\asdkmgPoly\asdkmgPoly.csproj]

Regression?

No response

Known Workarounds

No response

Configuration

i use .NET 7.
Windows 11 X64.

Other information

No response

Activity

  1. ghost added
    untriaged
    on Apr 28, 2023
  2. jkotas commented on Apr 28, 2023

    @jkotas
    Member

    error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease'

    The pre-built .NET runtime libraries that are included in native AOT package are built as "static link" (https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170#c-standard-library-stl-lib-files).

    The error is caused by ObjectArx library built as "dynamic link" that leads to the mismatch.

    Are you able to rebuild the ObjectArx library as "static link"? If you are using Visual Studio, set Properties / C/C++ / CodeGeneration / RuntimeLibrary to "Multi-threaded (/MT)" in your project file properties.

  3. AhmedZero commented on Apr 28, 2023

    @AhmedZero
    Author

    there is no source code for ObjectArx.

  4. jkotas commented on Apr 28, 2023

    @jkotas
    Member

    We do not have a great solution for this today. The potential workarounds that I can think of are:

    • Link ObjectArx into a separate .dll library that will get dynamically loaded using standard DllImport by your native AOT compiled .dll.
    • or, build this repo to create your own version of AOT package with matching C++ compiler options (the relevant C++ options are set here
      set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<AND:$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>,$<NOT:$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>>>:Debug>)
      ).

    #83611 tracks adding an option for compiling the unmanaged runtime with custom C++ compiler options that would help here.

  5. AhmedZero commented on Apr 28, 2023

    @AhmedZero
    Author
    • Link ObjectArx into a separate .dll library that will get dynamically loaded using standard DllImport by your native AOT compiled .dll.

    there is no DLL for rxapi.

    • or, build this repo to create your own version of AOT package with matching C++ compiler options (the relevant C++ options are set here

    That solution is only available.

    I hope we get a great solution in the future.

  6. jkotas commented on Apr 28, 2023

    @jkotas
    Member

    there is no DLL for rxapi.

    You can build it yourself.

    I hope we get a great solution in the future.

    +1. Resolving as duplicate of #83611

  7. ghost removed
    untriaged
    on Apr 28, 2023
  8. AhmedZero commented on Apr 28, 2023

    @AhmedZero
    Author

    I hope can build rxapi but there is no source code for rxapi. it's just headers and static library.

  9. jkotas commented on Apr 28, 2023

    @jkotas
    Member

    You can build it from the static library:

    • Create an empty .dll project
    • Add .def file to the project that list the entrypoints to export from .dll (e.g. acrxGetApiVersionImpl)
    • Add the rxapi static library to the linker inputs of this project.
  10. AhmedZero commented on Apr 28, 2023

    @AhmedZero
    Author

    I understand, thanks.

  11. ghost locked as resolved and limited conversation to collaborators on May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions