Thread: Compile pure C dll for C# DllImport with .Net Core on Ubuntu Linux

  1. #1
    Registered User
    Join Date
    Sep 2018
    Posts
    12

    Compile pure C dll for C# DllImport with .Net Core on Ubuntu Linux

    Hello all!
    My main.c in C code:
    Code:
    #include <stdio.h>void main()
    {
        printf("Hello world\n");
    }
    I'm running gcc main.c -o main.dll using Terminal. .Net Core console app:
    Code:
    using System;using System.Runtime.InteropServices;
    
    
    namespace dllimportc
    {
        class Program
        {
            static void Main()
            {
                Console.WriteLine("Hello World!");
                main();
                Console.ReadLine();
            }
            [DllImport("main.dll", EntryPoint = "main", CallingConvention = CallingConvention.Cdecl)]
    public static extern void main ();
        }
    }
    I've got an error:
    Exception has occurred: CLR/System.EntryPointNotFoundExceptionAn unhandled exception of type 'System.EntryPointNotFoundException' occurred in dllimportc.dll: 'Unable to find an entry point named 'main' in shared library 'main.dll'.'
    at dllimportc.Program.main()
    at dllimportc.Program.Main()
    How to run my C code from C#?

  2. #2
    Registered User
    Join Date
    Jun 2017
    Posts
    156
    A dll can have a DllMain function, not a main function, though it seems that it isn't necessary.
    DllMain entry point | Microsoft Docs
    PInvoke ( How to Call C from C# ) | Moy Blog

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ubuntu c file compile error gcc
    By Ph0x in forum C Programming
    Replies: 2
    Last Post: 09-27-2014, 03:41 PM
  2. Replies: 7
    Last Post: 09-18-2011, 11:45 AM
  3. Runs in Windows but not un Linux (Ubuntu)
    By Joelito in forum C++ Programming
    Replies: 5
    Last Post: 07-29-2009, 06:49 PM
  4. Error on Ubuntu/Linux but not Windows :O!
    By Akkernight in forum C++ Programming
    Replies: 9
    Last Post: 03-19-2009, 04:51 AM
  5. Replies: 5
    Last Post: 07-13-2008, 08:16 PM

Tags for this Thread