We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
How to implement gcc attribute((constructor)) when compiling dynamic libraries under Linux
1.create classlib
2.dotnet publish -r linux-bionic-arm64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true
gcc attribute((constructor))
no init
No response
The text was updated successfully, but these errors were encountered:
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.
Sorry, something went wrong.
You can use module initializer for this purpose.
Publish a project with module initializer:
$ dotnet new classlib -n ModInitLib $ cd ModInitLib $ cat > Class1.cs <<EOF using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; public static class LibraryInitializer { [ModuleInitializer] public static void Initialize() { Console.WriteLine("Library has been initialized (ModuleInitializer)!"); } [UnmanagedCallersOnly(EntryPoint = "say_hello")] public static void SayHello() { Console.WriteLine("Hello from ModInitLib!"); } } EOF $ dotnet publish -p:PublishAot=true -p:TargetName=libModInitLib -o dist --ucr
Link with some executable code:
$ cat > glue.c <<EOF #include <stdio.h> void say_hello(); int main(void) { say_hello(); return 0; } EOF $ cc -o glue glue.c -L./dist -lModInitLib $ ./glue Library has been initialized (ModuleInitializer)! Hello from ModInitLib!
No branches or pull requests
Description
How to implement gcc attribute((constructor)) when compiling dynamic libraries under Linux
Reproduction Steps
1.create classlib
2.dotnet publish -r linux-bionic-arm64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true
Expected behavior
gcc attribute((constructor))
Actual behavior
no init
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: