问题描述
这是我的.adb代码
与Ada.Text_IO;
包身体testDLL是
程序Print_Call是
begin
Ada.Text_IO.Put_Line(Hello World);
end Print_Call;
函数Add_Nums(A,B:Integer)return Integer是
begin
返回A + B;
end Add_Nums;
end testDLL;
我的.ads
package testDLL是
procedure Print_Call;
pragma export(dll,Print_Call,Print_Call);
函数Add_Nums(A,B:in Integer)return Integer;
pragma export(dll,add_Nums,Add_Nums);
end testDLL;
我的python
code> import ctypes
TestDLL = ctypes.WinDLL(libTestDLL.dll)
Print_Call = getattr(TestDLL,Print_Call @ 0)
Print_Call()
你可以看到我必须将@ 0添加到我的函数名称的末尾,但是当我将相同的代码移动到不同的编译器时,这似乎改变了。这给我造成了一些问题。我需要一个标准的格式或一种方法来消除所有的一切。
您可以通过编写指令的Link_Name和External_Name参数来控制对象名称,如下所示:
导出(C,Print_Call,Print_Call,Print_Call);
或者,如果您使用Ada2012,您可以使用方面来指定这些:
函数Add_Nums(A,B:in Integer)返回Integer
with Export,Convention => Ada,Link_Name => Add_Nums;
以下内容涵盖了Ada的界面编译指示:
这个线程涵盖了一些讨论,揭示了两者的差异:
Is there a simple way to prevent Ada names from getting mangled when creating an Ada DLL?
Here is my .adb code
with Ada.Text_IO;
package body testDLL is
procedure Print_Call is
begin
Ada.Text_IO.Put_Line("Hello World");
end Print_Call;
function Add_Nums(A,B : in Integer) return Integer is
begin
return A + B;
end Add_Nums;
end testDLL;
my .ads
package testDLL is
procedure Print_Call;
pragma export (dll, Print_Call, "Print_Call");
function Add_Nums(A,B : in Integer) return Integer;
pragma export (dll, Add_Nums, "Add_Nums");
end testDLL;
my python
import ctypes
TestDLL = ctypes.WinDLL ("libTestDLL.dll")
Print_Call = getattr(TestDLL, "Print_Call@0")
Print_Call()
you can see that I have to add '@0' to the end of my function name, but this seems to change when I move the same code to a different compiler. This is creating some problems for me. I need either a standard mangling format or a way to remove the mangling all together.
You can control the object name via the Link_Name and External_Name parameters of the pragma, writing it like so:
pragma Export (C, Print_Call, "Print_Call", "Print_Call");
Alternatively, if you're using Ada2012 you can use aspects to specify these:
function Add_Nums(A,B : in Integer) return Integer
with Export, Convention => Ada, Link_Name => "Add_Nums";
The following covers Ada's interfacing pragmas:http://www.ada-auth.org/standards/12rm/html/RM-J-15-5.html
This thread covers a little discussion revealing the differences of the two:https://groups.google.com/forum/?fromgroups=#!searchin/comp.lang.ada/opengl/comp.lang.ada/6IVlMbtvrrU/mv3UUiDg5RwJ
这篇关于防止在Ada DLL中被破坏的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!