Linking a C++ Program with an Ada Program If you have Rational Apex Duo for Rational Exec, it is possible to link a C++ program with an Ada program in the embedded environment. To do this, the following steps must be taken:
- 1 . C++ linking must be enabled in the Ada view.
To enable C++ linking, from the directory viewer use the Compile > Maintenance > Enable C++ Linking command. Once the dialog box is displayed, enter the names of the Ada view(s) in which you wish to link and specify the C++ model that was used to model the C++ views you are importing.
You can also invoke enable_cpp_linking from the command line. This command is described in detail in the Command Reference.
- 2 . Add the view with your C language code to the import list of the Ada view.
Select the Control > Show > Imports command to display the current imports. From the Imports dialog box, select Add Import. From the command line, use the import command.
- 3 . With c_support in the closure of the Ada program, you can link your Ada application with Compile > Link.
Importing C++ Functions
With C++, you can define the normal C names for a simple C++ function using the syntax:
extern "C" {...}
pragma Import (C, f);
The preferred mechanism for both ada83 and ada95 programs for interfacing to C functions is to use the pragma Import:
function C_Function returns integer; pragma Import(C, C_Function); -- name is c_function -- or -- pragma Import(C, C_Function, "C_Function"); -- name is C_Function
When using some of the older pragmas to identify the external C function it is possible that the following cryptic error message will be generated by the system linker:
"relocation truncated to fit: 0x0a MTcube".
This is because the required "." in the name will not be inserted. For example:
pragma Interface(C, C_Function); pragma Interface_Name(C_Function, "c_function"); -- not correct pragma Interface_Name(C_Function, ".c_function"); -- correctIt is recommended that only pragma Import be used.
In previous releases of Apex the System.Unix_C.Subp_Prefix or Interfaces.C.Subp_Prefix was available for use with these non-recommended pragmas. These objects have been removed since they are not within the Ada standards and the pragma Import solution as defined by the Ada95 LRM is the Apex preferred solution.
Rational Software Corporation http://www.rational.com support@rational.com techpubs@rational.com Copyright © 1993-2002, Rational Software Corporation. All rights reserved. |