POSIX source to dll (Full Version)

All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum



Message


Krabi -> POSIX source to dll (Oct. 2, '06, 6:51:53 AM)

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'.




Krabi -> RE: POSIX source to dll (Oct. 2, '06, 7:02:40 AM)

Maybe also:
1) BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
2) #define DLL_EXPORT __declspec(dllexport)
must be added some how?




markfunk -> RE: POSIX source to dll (Oct. 2, '06, 9:31:55 AM)

You cannot use the default Interix tools to build Win32 objects.
The gcc that ships with Interix is set up to build Interix objects, not Win32.
Any .so's created in Interix can only be used in the Interix environment.
Think of Interix as another version of UNIX.

You could either build your library using Win32 development tools (cygwin, mingw, MKS)
or you could try "mixed mode" build tools available in SUA on Vista or Windows Server 2003 R2.
(SUA = subsystem for UNIX applications).
This "mixed mode" allows you to use Interix functionality in a Win32 application.
But there are several caveats and restrictions. (eg. you have to avoid conflicts between
the Interix and Win32 libraries)




Krabi -> RE: POSIX source to dll (Oct. 3, '06, 4:24:19 AM)

I used cygwin today and with a few changes in my code and all fine. I tried it only with C#! I am going to try with JNI now.
But what about future? Will Interix do work to resolve this like problems in future?




Page: [1]



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.016