comp.lang.ada
 help / color / mirror / Atom feed
* Using dll from a C# code
@ 2012-02-29 11:52 Rego, P.
  2012-02-29 20:00 ` Shark8
  2012-03-02  3:37 ` mjamesb
  0 siblings, 2 replies; 14+ messages in thread
From: Rego, P. @ 2012-02-29 11:52 UTC (permalink / raw)


Hello,

I have a method in C# which I need to export to Ada using a dll. Maybe 

// simple.cs
// compile with csc /t:library simple.cs
using System;
public class VerifyClass{
	public bool Verify(){
		return true;
	}
}

In order to use the function Verify() in Ada, I need to import this to something like 
-- simple.ads
package Simple is
	function Verify return Boolean;
	pragma Import
	(Convention    => dll,
	Entity        => Verify,
	External_Name => "Verify");
end Simple;

And I could use with 
-- main.adb
-- build with gnatmake main -largs -lsimple
with Text_IO; use Text_IO;
with Simple; use Simple;
procedure Main is
begin
	Put_Line (Boolean'Image (Verify));
end Main;	


When I build the Ada with 
gnatmake main -largs -lsimple

the compiler returns me 
./main.o(.text+0xd6):main.adb: undefined reference to `Verify@0'

So what have I missed? Maybe the C# code structure should be changed?



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-02-29 11:52 Using dll from a C# code Rego, P.
@ 2012-02-29 20:00 ` Shark8
  2012-03-01  2:26   ` Rego, P.
  2012-03-02  3:37 ` mjamesb
  1 sibling, 1 reply; 14+ messages in thread
From: Shark8 @ 2012-02-29 20:00 UTC (permalink / raw)


On Feb 29, 5:52 am, "Rego, P." <pvr...@gmail.com> wrote:
> Hello,
>
> I have a method in C# which I need to export to Ada using a dll. Maybe
>
> // simple.cs
> // compile with csc /t:library simple.cs
> using System;
> public class VerifyClass{
>         public bool Verify(){
>                 return true;
>         }
>
> }
>
> In order to use the function Verify() in Ada, I need to import this to something like
> -- simple.ads
> package Simple is
>         function Verify return Boolean;
>         pragma Import
>         (Convention    => dll,
>         Entity        => Verify,
>         External_Name => "Verify");
> end Simple;
>
> And I could use with
> -- main.adb
> -- build with gnatmake main -largs -lsimple
> with Text_IO; use Text_IO;
> with Simple; use Simple;
> procedure Main is
> begin
>         Put_Line (Boolean'Image (Verify));
> end Main;
>
> When I build the Ada with
> gnatmake main -largs -lsimple
>
> the compiler returns me
> ./main.o(.text+0xd6):main.adb: undefined reference to `Verify@0'
>
> So what have I missed? Maybe the C# code structure should be changed?

You have to be sure you are using the compiler for .NET; I think
there's something about qualifying names too, but I don't remember
what. You may want to check out the import pragma on page 16 in this
pdf: http://www.usafa.edu/df/dfe/dfer/centers/accr/docs/carlisle2006b.pdf




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-02-29 20:00 ` Shark8
@ 2012-03-01  2:26   ` Rego, P.
  2012-03-01  5:38     ` Gautier write-only
  0 siblings, 1 reply; 14+ messages in thread
From: Rego, P. @ 2012-03-01  2:26 UTC (permalink / raw)


> You have to be sure you are using the compiler for .NET; I think
> there's something about qualifying names too, but I don't remember
> what. You may want to check out the import pragma on page 16 in this
> pdf: http://www.usafa.edu/df/dfe/dfer/centers/accr/docs/carlisle2006b.pdf

Quite interesting this paper. But I still could not import the function with success. Actually I changed the simple.cs to
// simple.cs
// compile with csc /t:library simple.cs
namespace Simple{
        public class VerifyClass{
                public static bool Verify(){
                return true;
        }
        }
}

So when I make gnatmake main -largs -lsimple, it returns me
gcc -c main.adb
gcc -c simple.ads
gnatbind -x main.ali
gnatlink main.ali -lsimple
.\main.o:main.adb:(.text+0x21): undefined reference to `Verify@0'
collect2: ld returned 1 exit status
gnatlink: error when calling C:\GNAT\2011\bin\gcc.exe
gnatmake: *** link failed.

I sense that the problem is a tiny mistake (but where?) 



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01  2:26   ` Rego, P.
@ 2012-03-01  5:38     ` Gautier write-only
  2012-03-01 11:41       ` Rego, P.
  0 siblings, 1 reply; 14+ messages in thread
From: Gautier write-only @ 2012-03-01  5:38 UTC (permalink / raw)


On 1 mar, 03:26, "Rego, P." <pvr...@gmail.com> wrote:

> So when I make gnatmake main -largs -lsimple, it returns me
> gcc -c main.adb
> gcc -c simple.ads
> gnatbind -x main.ali
> gnatlink main.ali -lsimple
> .\main.o:main.adb:(.text+0x21): undefined reference to `Verify@0'
> collect2: ld returned 1 exit status
> gnatlink: error when calling C:\GNAT\2011\bin\gcc.exe
> gnatmake: *** link failed.
>
> I sense that the problem is a tiny mistake (but where?)

Are actually using the .NET-targetting GNAT ?
I have the impression you are using the plain Windows one, it should
be something like dotnetgnatmake.exe - look into your C:\GNAT\2011\bin
directory.
I suppose you also installed GNAT for .NET ?
_________________________
Gautier's Ada programming
http://sf.net/users/gdemont



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01  5:38     ` Gautier write-only
@ 2012-03-01 11:41       ` Rego, P.
  2012-03-01 13:16         ` Georg Bauhaus
  2012-03-01 14:38         ` gautier_niouzes
  0 siblings, 2 replies; 14+ messages in thread
From: Rego, P. @ 2012-03-01 11:41 UTC (permalink / raw)


> Are actually using the .NET-targetting GNAT ?
Actually no. I am using native .NET for generating the dll. So I just run C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 /t:library simple.cs
And soon after I run gnatmake main -largs -lsimple

> I have the impression you are using the plain Windows one, it should
> be something like dotnetgnatmake.exe - look into your C:\GNAT\2011\bin
> directory.
> I suppose you also installed GNAT for .NET ?
I don't have it installed. Should I use it to create the dll?



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01 11:41       ` Rego, P.
@ 2012-03-01 13:16         ` Georg Bauhaus
  2012-03-01 14:38         ` gautier_niouzes
  1 sibling, 0 replies; 14+ messages in thread
From: Georg Bauhaus @ 2012-03-01 13:16 UTC (permalink / raw)


On 01.03.12 12:41, Rego, P. wrote:
>> Are actually using the .NET-targetting GNAT ?
> Actually no. I am using native .NET for generating the dll. So I just run C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 /t:library simple.cs
> And soon after I run gnatmake main -largs -lsimple
> 
>> I have the impression you are using the plain Windows one, it should
>> be something like dotnetgnatmake.exe - look into your C:\GNAT\2011\bin
>> directory.
>> I suppose you also installed GNAT for .NET ?
> I don't have it installed. Should I use it to create the dll?

Isn't a .NET DLL actually different from a more traditional
DLL, i.e., a thing to be JIT compiled into executable code?



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01 11:41       ` Rego, P.
  2012-03-01 13:16         ` Georg Bauhaus
@ 2012-03-01 14:38         ` gautier_niouzes
  2012-03-01 15:15           ` Rego, P.
  1 sibling, 1 reply; 14+ messages in thread
From: gautier_niouzes @ 2012-03-01 14:38 UTC (permalink / raw)


Le jeudi 1 mars 2012 12:41:55 UTC+1, Rego, P. a écrit :

> Actually no. I am using native .NET for generating the dll. So I just run C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 /t:library simple.cs

A .NET DLL is not a traditional DLL and has not Intel machine code in it.
It was called DLL just to avoid disturbing some people (and confusing other). 

See here, under ".NET assembly" for more infos:
http://support.microsoft.com/kb/815065/en-us

HTH 
_________________________ 
Gautier's Ada programming 
http://freecode.com/users/gdemont 



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01 14:38         ` gautier_niouzes
@ 2012-03-01 15:15           ` Rego, P.
  2012-03-01 16:24             ` Gautier write-only
  2012-03-01 16:25             ` Georg Bauhaus
  0 siblings, 2 replies; 14+ messages in thread
From: Rego, P. @ 2012-03-01 15:15 UTC (permalink / raw)


Em quinta-feira, 1 de março de 2012 11h38min52s UTC-3, gautier...@hotmail.com  escreveu:
> Le jeudi 1 mars 2012 12:41:55 UTC+1, Rego, P. a écrit :
> 
> > Actually no. I am using native .NET for generating the dll. So I just run C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 /t:library simple.cs
> 
> A .NET DLL is not a traditional DLL and has not Intel machine code in it.
> It was called DLL just to avoid disturbing some people (and confusing other). 

I don't get it. So is not possible to import a C#/.NET method in dll in an Ada code?



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01 15:15           ` Rego, P.
@ 2012-03-01 16:24             ` Gautier write-only
  2012-03-02 20:03               ` Rego, P.
  2012-03-01 16:25             ` Georg Bauhaus
  1 sibling, 1 reply; 14+ messages in thread
From: Gautier write-only @ 2012-03-01 16:24 UTC (permalink / raw)


On 1 mar, 16:15, "Rego, P." <pvr...@gmail.com> wrote:
> Em quinta-feira, 1 de março de 2012 11h38min52s UTC-3, gautier...@hotmail.com  escreveu:
>
> > Le jeudi 1 mars 2012 12:41:55 UTC+1, Rego, P. a écrit :
>
> > > Actually no. I am using native .NET for generating the dll. So I just run C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 /t:library simple.cs
>
> > A .NET DLL is not a traditional DLL and has not Intel machine code in it.
> > It was called DLL just to avoid disturbing some people (and confusing other).
>
> I don't get it. So is not possible to import a C#/.NET method in dll in an Ada code?

Yes, you can :-).
What you can't is mixing different machines.

Your PC with an Intel processor and Windows is a different machine
than the .NET virtual platform, with MSIL as machine code.
If you compile a module with language X into machine code for machine
A, and another module with language Y into another machine code,
machine B/=A, you won't be able to make both work together.
For instance you won't make a Commodore 64 machine code and a PC
machine code work together.
Perhaps if you think to a Commodore 64 emulator instead of the .NET
platform, it will be clearer.
So you need to find a common machine for compiling both languages.
For C#, only one choice: MSIL
For Ada, you have plenty of choices: Windows&Intel32/64,
Linux&Intel32/64/..., MacOSX&PowerPC/Intel, JVM, MSIL, UNIX,
OpenVMS, ...
And, hurray, you realize there is one common target machine in the
list: MSIL.
So you have to use the GNAT-for-.NET, not the GNAT-for-Windows.

Got it ?



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01 15:15           ` Rego, P.
  2012-03-01 16:24             ` Gautier write-only
@ 2012-03-01 16:25             ` Georg Bauhaus
  2012-03-02 21:15               ` Rego, P.
  1 sibling, 1 reply; 14+ messages in thread
From: Georg Bauhaus @ 2012-03-01 16:25 UTC (permalink / raw)


On 01.03.12 16:15, Rego, P. wrote:
> Em quinta-feira, 1 de mar�o de 2012 11h38min52s UTC-3, gautier...@hotmail.com  escreveu:
>> Le jeudi 1 mars 2012 12:41:55 UTC+1, Rego, P. a �crit :
>>
>>> Actually no. I am using native .NET for generating the dll. So I just run C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 /t:library simple.cs
>>
>> A .NET DLL is not a traditional DLL and has not Intel machine code in it.
>> It was called DLL just to avoid disturbing some people (and confusing other). 
> 
> I don't get it. So is not possible to import a C#/.NET method in dll in an Ada code?

It is possible to import a method of a .NET type into a native
Ada program if it is possible to import a method of a .NET type
into a native C++ program, i.e. not into a C++/CLI program,
but into a C++ program that is compiled with a C++ compiler
that generates processor instructions, not .NET byte code.

Similar possibilities exist for importing methods of a compiled
Java class (JVM byte code) into an Ada program that is compiled
into Intel/AMD processor instructions.

IINM, DLL in
- .NET means libraries of O-O types with methods, in byte code.
- Win32 means libraries of functions, processor instructions.

The Windows(TM) platforms are many. It is necessary to pick
compilers for compatible targets. For example, A# (GNAT for .NET)
with one of the .NET compilers by Microsoft.

But then, using .NET types from A# programs means with-ing
packages of .NET types, not importing single methods.

public class VerifyClass { ... }

will become a tagged type on the Ada side, and you use
this Ada type almost as usual in O-O Ada.  There will a pointer to
the reference handling objects of imported type VerifyClass.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-02-29 11:52 Using dll from a C# code Rego, P.
  2012-02-29 20:00 ` Shark8
@ 2012-03-02  3:37 ` mjamesb
  2012-03-02 21:17   ` Rego, P.
  1 sibling, 1 reply; 14+ messages in thread
From: mjamesb @ 2012-03-02  3:37 UTC (permalink / raw)


> I have a method in C# which I need to export to Ada using a dll. Maybe

If you're willing to try some MS C++ then the following item might
be useful:

  http://stackoverflow.com/questions/1823466/how-to-call-a-net-dll-from-a-win32-process

the comment portion of which is mostly (it has a code example):

"Another option is to use C++/CLI as a bridge. People are mostly
  familiar with using it to wrap unmanaged APIs to expose to managed
  code, but it actually works both ways - it is possible to compile
  with /clr, and yet produce a .dll assembly with plain unmanaged
  exports, which can be called from unmanaged code as usual.
   ...
  In practice it will load CLR runtime into the calling process
  (unless it's already loaded there) and dispatch from native code
  to managed code transparently - all the magic is done by C++/CLI
  compiler."

Have fun.

  - mjamesb




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01 16:24             ` Gautier write-only
@ 2012-03-02 20:03               ` Rego, P.
  0 siblings, 0 replies; 14+ messages in thread
From: Rego, P. @ 2012-03-02 20:03 UTC (permalink / raw)


> Your PC with an Intel processor and Windows is a different machine
> than the .NET virtual platform, with MSIL as machine code.
> If you compile a module with language X into machine code for machine
> A, and another module with language Y into another machine code,
> machine B/=A, you won't be able to make both work together.
> For instance you won't make a Commodore 64 machine code and a PC
> machine code work together.
> Perhaps if you think to a Commodore 64 emulator instead of the .NET
> platform, it will be clearer.
> So you need to find a common machine for compiling both languages.
> For C#, only one choice: MSIL
> For Ada, you have plenty of choices: Windows&Intel32/64,
> Linux&Intel32/64/..., MacOSX&PowerPC/Intel, JVM, MSIL, UNIX,
> OpenVMS, ...
> And, hurray, you realize there is one common target machine in the
> list: MSIL.
> So you have to use the GNAT-for-.NET, not the GNAT-for-Windows.
> 
> Got it ?

Got it. So the target application would have to be recompiled using gnat-for-.net. 



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-01 16:25             ` Georg Bauhaus
@ 2012-03-02 21:15               ` Rego, P.
  0 siblings, 0 replies; 14+ messages in thread
From: Rego, P. @ 2012-03-02 21:15 UTC (permalink / raw)


Em quinta-feira, 1 de março de 2012 13h25min36s UTC-3, Georg Bauhaus  escreveu:
> On 01.03.12 16:15, Rego, P. wrote:
> > Em quinta-feira, 1 de março de 2012 11h38min52s UTC-3, gautier...@hotmail.com  escreveu:
> >> Le jeudi 1 mars 2012 12:41:55 UTC+1, Rego, P. a écrit :
> >>
> >>> Actually no. I am using native .NET for generating the dll. So I just run C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 /t:library simple.cs
> >>
> >> A .NET DLL is not a traditional DLL and has not Intel machine code in it.
> >> It was called DLL just to avoid disturbing some people (and confusing other). 
> > 
> > I don't get it. So is not possible to import a C#/.NET method in dll in an Ada code?
> 
> It is possible to import a method of a .NET type into a native
> Ada program if it is possible to import a method of a .NET type
> into a native C++ program, i.e. not into a C++/CLI program,
> but into a C++ program that is compiled with a C++ compiler
> that generates processor instructions, not .NET byte code.
> 
> Similar possibilities exist for importing methods of a compiled
> Java class (JVM byte code) into an Ada program that is compiled
> into Intel/AMD processor instructions.
> 
> IINM, DLL in
> - .NET means libraries of O-O types with methods, in byte code.
> - Win32 means libraries of functions, processor instructions.
> 
> The Windows(TM) platforms are many. It is necessary to pick
> compilers for compatible targets. For example, A# (GNAT for .NET)
> with one of the .NET compilers by Microsoft.
> 
> But then, using .NET types from A# programs means with-ing
> packages of .NET types, not importing single methods.
> 
> public class VerifyClass { ... }
> 
> will become a tagged type on the Ada side, and you use
> this Ada type almost as usual in O-O Ada.  There will a pointer to
> the reference handling objects of imported type VerifyClass.

I understand. Thanks.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Using dll from a C# code
  2012-03-02  3:37 ` mjamesb
@ 2012-03-02 21:17   ` Rego, P.
  0 siblings, 0 replies; 14+ messages in thread
From: Rego, P. @ 2012-03-02 21:17 UTC (permalink / raw)


Em sexta-feira, 2 de março de 2012 00h37min25s UTC-3, mjamesb  escreveu:
> > I have a method in C# which I need to export to Ada using a dll. Maybe
> 
> If you're willing to try some MS C++ then the following item might
> be useful:
> 
>   http://stackoverflow.com/questions/1823466/how-to-call-a-net-dll-from-a-win32-process
> 
> the comment portion of which is mostly (it has a code example):
> 
> "Another option is to use C++/CLI as a bridge. People are mostly
>   familiar with using it to wrap unmanaged APIs to expose to managed
>   code, but it actually works both ways - it is possible to compile
>   with /clr, and yet produce a .dll assembly with plain unmanaged
>   exports, which can be called from unmanaged code as usual.
>    ...
>   In practice it will load CLR runtime into the calling process
>   (unless it's already loaded there) and dispatch from native code
>   to managed code transparently - all the magic is done by C++/CLI
>   compiler."
> 
> Have fun.
> 
>   - mjamesb



Em sexta-feira, 2 de março de 2012 00h37min25s UTC-3, mjamesb  escreveu:
> > I have a method in C# which I need to export to Ada using a dll. Maybe
> 
> If you're willing to try some MS C++ then the following item might
> be useful:
> 
>   http://stackoverflow.com/questions/1823466/how-to-call-a-net-dll-from-a-win32-process
> 
> the comment portion of which is mostly (it has a code example):
> 
> "Another option is to use C++/CLI as a bridge. People are mostly
>   familiar with using it to wrap unmanaged APIs to expose to managed
>   code, but it actually works both ways - it is possible to compile
>   with /clr, and yet produce a .dll assembly with plain unmanaged
>   exports, which can be called from unmanaged code as usual.
>    ...
>   In practice it will load CLR runtime into the calling process
>   (unless it's already loaded there) and dispatch from native code
>   to managed code transparently - all the magic is done by C++/CLI
>   compiler."
> 
> Have fun.
> 
>   - mjamesb

The idea of the bridge is interesting.



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-03-02 21:17 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-29 11:52 Using dll from a C# code Rego, P.
2012-02-29 20:00 ` Shark8
2012-03-01  2:26   ` Rego, P.
2012-03-01  5:38     ` Gautier write-only
2012-03-01 11:41       ` Rego, P.
2012-03-01 13:16         ` Georg Bauhaus
2012-03-01 14:38         ` gautier_niouzes
2012-03-01 15:15           ` Rego, P.
2012-03-01 16:24             ` Gautier write-only
2012-03-02 20:03               ` Rego, P.
2012-03-01 16:25             ` Georg Bauhaus
2012-03-02 21:15               ` Rego, P.
2012-03-02  3:37 ` mjamesb
2012-03-02 21:17   ` Rego, P.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox