Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Allow creating native library (static or shared) #1285

Closed

Description

@DemiMarie

It should be possible to create a library (either static or dynamic) which exposes a C API, and which does not require callers to be aware that it is not written in C.

Activity

  1. jkotas commented on May 17, 2016

    @jkotas
    Member

    Thank you for talking a look at the project. First class support for building libraries like this is definitely something we would like to support in CoreRT eventually. This involves providing a different version of startup code (src\Native\Bootstrap) and build scripts.

  2. modified the milestone: on May 17, 2016
  3. jkotas commented on Jul 11, 2016

    @jkotas
    Member

    #1498 is one of the problems that needs to be fixed to make this work.

  4. added this to the Future milestone on Oct 20, 2016
  5. MihaMarkic commented on Jan 14, 2017

    @MihaMarkic

    This is a great proposition and would be of immense value. Hopefully it will be implemented.

  6. allquixotic commented on Jul 16, 2017

    @allquixotic

    Now that #1498 is fixed, what is left to make this happen? Can any of the core devs give kind of a roadmap for how this could be implemented? Are there any known chunks of work besides #1498 that are pending before this can be implemented in a fairly straightforward way?

  7. jkotas commented on Jul 17, 2017

    @jkotas
    Member

    Here is what's needed to make this happen. For now, I would worry about RyuJIT codegen only for all of this.

    • Create clone of the bootstrap code for dlls: Copy src\Native\Bootstrap\base to src\Native\Bootstrap\dll, rename bootstrapper to bootstrapperdll in the CMakeLists.txt, add add_subdirectory(bootstrapperdll) to src\Native\Bootstrap\CMakeLists.txt to add it to the build.

    • Modify the bootstrap code for dlls to not have main method: Add add_definitions(-DCORERT_DLL) to src\Native\Bootstrap\dll\CMakeLists.txt and change src\Native\Bootstrap\main.cpp:

    extern "C" void InitializeModules(void* osModule, void ** modules, int count, void ** pClasslibFunctions, int nClasslibFunctions);
    
    #ifdef CORERT_DLL
    #if defined(_WIN32)
    #define wmain CoreRT_wmain
    #else
    #define main CoreRT_main
    #endif
    #endif
    
    • Change build scripts under https://github.com/dotnet/corert/tree/master/src/BuildIntegration to not produce native .exe, but produce native .dll instead when a new NativeDll msbuild property is set

    Now, you should be able to produce native .dll out of managed .exe. This native .dll should have CoreRT_wmain entrypoint that you can use to run it. You should be also able to export extern "C" entrypoints from it using NativeCallable attribute that you can call afer the CoreRT_wmain have finished.

    The next step is get rid of the fake main method and polish this so that you can actually build the native .dll from managed library:

    @MichalStrehovsky Feel free to edit this post with anything else you can think of.

  8. tonerdo commented on Jul 24, 2017

    @tonerdo
    Contributor

    @jkotas I'd love to pick this up. I'd get started on it, right away

  9. jkotas commented on Jul 24, 2017

    @jkotas
    Member

    @tonerdo It's yours. Thanks!

  10. bazzilic commented on Jul 26, 2017

    @bazzilic

    @tonerdo thanks for working on that! Been looking for a way to produce native libraries for the last week -- with no useful results. Hope you can put a prototype together soon, I'd be happy to test it!

  11. tonerdo commented on Jul 26, 2017

    @tonerdo
    Contributor

    @bazzilic Yeah I saw your message in gitter, was going to respond. I've started working on it and will let you know once I got something

  12. 158 remaining items

  13. tonerdo commented on Nov 12, 2017

    @tonerdo
    Contributor

    @nattress after a bit of google searches I've been able to come to the conclusion that the static library that contains that symbol wasn't compiled with position independent code in mind. I should mention that after pulling the latest master the problem symbol is no longer __GetNonGCStaticBase_S_P_CoreLib_System_AppContext but now __NewArr1___Array<Object>.

    Full error output:

    /usr/bin/ld: obj/Debug/netstandard2.0/native/cslib.o: relocation R_X86_64_PC32 against symbol `__NewArr1___Array<Object>' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: final link failed: Bad value
    
  14. jkotas commented on Nov 21, 2017

    @jkotas
    Member

    @tonerdo Could you open github issues on the followup up work items for this that you are aware of, and link them to this issue?

  15. tonerdo commented on Nov 21, 2017

    @tonerdo
    Contributor

    @jkotas will do 👍

  16. sgf commented on Mar 17, 2018

    @sgf

    if could be create native lib,thats will be great !!!

  17. MichalStrehovsky commented on Jun 25, 2018

    @MichalStrehovsky
    Member

    We now have small workitems tracking the remaining work here (see issues linking to this). Let's not have duplicate issues open.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions