问题描述
我试图创建一个完全托管在Eclipse中的程序,以C ++开始,并调用Ada。我有GNATBench加载,并可以运行Ada程序没有问题。我不能做的是有一个C ++项目调用一个Ada项目。
I am trying to create a program that is completely hosted in Eclipse, starts in C++, and calls Ada. I have GNATBench loaded, and can run Ada programs without a problem. What I cannot do is have a C++ project call an Ada project.
在狩猎之后,我使用make文件找到并执行了下面的代码。
After hunting around, I found and executed the code shown below using a make file.
我也发现了一个帖子,表明我的目标已经完成。
I also found a post stating that my goal has been done.
我需要包含哪些内容才能让Eclipse中的C ++调用Ada在Eclipse?
What else do I need to include to have C++ in Eclipse call Ada in Eclipse?
使用MAKE文件:
$ c++ -c test.cc
$ gnatgcc -c test_subr
$ gnatbind -n test_subr
$ gnatgcc -c b~test_subr
$ gnatlink -o main test.o test_subr.ali --link=c++
$ ./main
CPP代码:
CPP Code:
//main.cc
#include extern "C" void adainit(void);
#include extern "C" void adafinal(void);
#include extern "C" void ada_subroutine(void);
int main(int argc, char **argv)
{
puts("C++ main");
adainit();
ada_subroutine();
adafinal();
puts("C++ done");
return 0;
}
Ada代码:
package Test_Subr is
procedure Ada_Subroutine;
pragma export(CPP, Ada_Subroutine);
end Test_Subr;
with Ada.Text_IO;
use Ada.Text_IO;
package body Test_Subr is
procedure Ada_Subroutine is
begin
put("IN ADA");
end Ada_Subroutine;
end Test_Subr;
推荐答案
? (IIRC,C ++链接可能会非常严重。)
Have you tried using the External_Name parameter of the Export pragma? (IIRC, C++ linkages can get quite mangled.)
pragma Export
( Convention => CPP,
Entity => Ada_Subroutine,
External_Name => "Ada_Subroutine "
);
这篇关于在Eclipse中从C ++调用Ada的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!