Hello.
I developed shared library for Linux. This shared library contains functions that are in POSIX compatible and are used by Java (through JNI) on linux. Now I decided port that library to Win32. I looked around and find that simplest is that I use Interix environment to build that library for windows. Same makefiles what are written for Linux building systems can build .so file successfully.
What I must to do next, when I want to use this library by Java on Windows machine? Maybe C#.Net is also useful.
About my experience I can say that I have made before some C# and Java projects. Those projects use dll-s for accessing my own APIs and they work correctly. My question is, how can I write wrapper for POSIX functionalities and put those wrapper functions inside dll?
And a bit code:
/*
Test.h
It's not JNI compatible yet! But what about C#?
*/
extern "C" {
int Number(int nr);
}
-----------
/*
Test.cpp
*/
#include "Test.h"
int Number(int nr)
{
nr++;
nr++;
return nr;
}
-----------
#Makefile
all: compile linking striping dll sharp
compile:
g++ -fPIC -c Test.cpp -o Test.o
linking:
g++ -shared -Wl,-soname,libTest.so Test.o -o libTest.so
striping:
strip libTest.so
dll:
#Is it correct? Is Interix .so in dll format?
cp libTest.so Test.dll
sharp:
#Copy dll in to charpdevelop project binary directory
cp Test.dll ./InterixTest/bin/Debug
/*
Test.cs
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
namespace InterixTest
{
public class Test
{
public Test(){}
[DllImport("Test.dll")] protected static extern
int Number(int nr);
public int CallNumber(int nr)
{
return Number(nr);
}
}
}
And error what .Net executing give:
Exception System.EntryPointNotFoundException was thrown in debuggee:
Unable to find an entry point named 'Number' in DLL 'Test.dll'.
|