Call C lib from Mono in Linux
Posted Date Unknown Arun Kumar 1 Comment

Hello,

I created one Mono application to call C method from a shared library in Linux. My code is listed below

using System;
using System.Runtime.InteropServices;


namespace testConsole
{
    class MainClass
    {
        [DllImport("libTest.so",CharSet=CharSet.Auto,CallingConvention =CallingConvention.Cdecl, EntryPoint="testMethod",SetLastError=true ) ]
        public static extern void testMethod();

        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello World!");
            testMethod();

            Console.WriteLine ("Hello World!");
        }
    }
}


and my shared library code like this

#ifndef SFLOW_H
#define SFLOW_H 1

#if defined(__cplusplus)
extern "C" {
#endif

void testMethod()
{

}

extern void testMethod1()
{
printf("This from C");
}

#if defined(__cplusplus)
}  /* extern "C" */
#endif

#endif /* SFLOW_H */

And I run the application I can load the libarary to C# using DllImport, But  unable to call its method.How t call that testMethod() function from my mono code?

Please help me...



The error like this

Hello World!

Unhandled Exception: System.EntryPointNotFoundException: testMethod
  at (wrapper managed-to-native) testConsole.MainClass:testMethod ()
  at testConsole.MainClass.Main (System.String[] args) [0x0000a] in /home/arun/Projects/testConsole/testConsole/Main.cs:15
[ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: testMethod
  at (wrapper managed-to-native) testConsole.MainClass:testMethod ()
  at testConsole.MainClass.Main (System.String[] args) [0x0000a] in /home/arun/Projects/testConsole/testConsole/Main.cs:15

Press any key to continue...

See All Responses Below...
Author
Message Rating
Posted on: 18/06/2012
The entry point method signature for a shared library in Linux might be different form a Windows DLL ( DLLMain() ). Please check it..

Tom

Please Login to Post Your Comments
Name (Max. 100 characters)
Please post your comments here
Select Language
Comments
Attach File(Max. Size: 2 MB)
A few simple rules when posting your Comments,
  1. Please post only answers relevant to the topic of discussion.
  2. Please dont misuse this site or do not be abusive, offensive, inappropriate,harass anyone on the boards or post ads or spam. Doing so will delete your inappropriate messages and will block or delete your account on this site. 

TekTipsDownload
GateExam
Academic Projects
TekTipsExperts



 
Site optimized for IE7, 1280 X 768 and above. Copyright © 2010 - 2018 KTS InfoTech
Site Developed Using KTS WebCloud