(This post is related to two earlier posts by me, "Linking Ada to Pascal" and 'Where is documentation for "new argument to _p_initialize (@)" PCStrings.')
I've had some success here. The following two files (Pascal main program) and compile commands work.
<file pascalcallsada.pas> program pascalcallsada (input, output);
procedure youradapackagesubroutine; external name 'myadapackagesubroutine'; procedure adainit; external name 'adainit'; procedure adafinal; external name 'adafinal';
begin adainit; writeln('Hello from pascalcallsada.'); youradapackagesubroutine; writeln('Goodbye from Pascal main program.'); adafinal; end.
<file myadapackage.ads> package myadapackage is
procedure myadapackagesubroutine; pragma Export(Convention => C, Entity => myadapackagesubroutine, External_Name => "myadapackagesubroutine");
end myadapackage;
<file myadapackage.adb> with Ada.Text_IO; use Ada.Text_IO;
package body myadapackage is
procedure myadapackagesubroutine is begin Put_Line("Hello from myadapackagesubroutine."); end myadapackagesubroutine;
begin Put_Line("Initializing myadapackage."); end myadapackage;
<Compile commands> gpc -c pascalcallsada.pas gnatmake -c myadapackage.adb gnatmake -c myadaprogram.adb gnatbind -n myadapackage.ali myadaprogram.ali gnatlink myadaprogram.ali pascalcallsada.o `gpc -print-file- name=libgpc.a` \ -o mypascalprogram
<Out from running> Initializing myadapackage. Hello from pascalcallsada. Hello from myadapackagesubroutine. Goodbye from Pascal main program.
Jerry
lanceboyle@qwest.net wrote:
(This post is related to two earlier posts by me, "Linking Ada to Pascal" and 'Where is documentation for "new argument to _p_initialize (@)" PCStrings.')
I've had some success here. The following two files (Pascal main program) and compile commands work.
Good to hear so.
<snip>
<Compile commands> gpc -c pascalcallsada.pas gnatmake -c myadapackage.adb gnatmake -c myadaprogram.adb gnatbind -n myadapackage.ali myadaprogram.ali gnatlink myadaprogram.ali pascalcallsada.o `gpc -print-file-name=libgpc.a` \ -o mypascalprogram
Without any knowledge of Ada, I am trying to understand what exactly happens here, so I have the following questions.
1. gnatmake is the command to use to compile a .adb file into a .o file ? 2. what does gnatbind do ? is it possible to add -v to see what exactly it does ? 3. same question for gnatlink. I assume it calls ld, adding Ada and OS runtime stuff ?
With this information it may be possible to add Ada support to gp, the gpc make/build utility (especially since the main program is Pascal in this example).
Regards,
Adriaan van Os
On Jan 18, 2006, at 2:20 AM, Adriaan van Os wrote:
lanceboyle@qwest.net wrote:
(This post is related to two earlier posts by me, "Linking Ada to Pascal" and 'Where is documentation for "new argument to _p_initialize (@)" PCStrings.')
I've had some success here. The following two files (Pascal main program) and compile commands work.
Good to hear so.
<snip>
<Compile commands> gpc -c pascalcallsada.pas gnatmake -c myadapackage.adb gnatmake -c myadaprogram.adb gnatbind -n myadapackage.ali myadaprogram.ali gnatlink myadaprogram.ali pascalcallsada.o `gpc -print-file- name=libgpc.a` \ -o mypascalprogram
Without any knowledge of Ada, I am trying to understand what exactly happens here, so I have the following questions.
- gnatmake is the command to use to compile a .adb file into a .o
file ? 2. what does gnatbind do ? is it possible to add -v to see what exactly it does ? 3. same question for gnatlink. I assume it calls ld, adding Ada and OS runtime stuff ?
With this information it may be possible to add Ada support to gp, the gpc make/build utility (especially since the main program is Pascal in this example).
I've been dabbling with Ada for a while but only recently decided to try to get serious about it. In my case, that also means using tons of Pascal code that I don't want to re-write. So I'm having to learn a bit about stuff that I never bothered with before. This a way to say that I'm just a little ways into Ada and the GNAT (GNU Ada) build system etc. so please be wary of my answers. Also, I don't know C well.
Useful references include "GNAT User's Guide for Unix Platforms" at http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gnat_ug_unx/index.html#Top and "The Big Online Book of Linux Ada Programming" at http:// www.oopweb.com/Ada/Documents/AdaLinux/VolumeFrames.html?/Ada/ Documents/AdaLinux/Volume/12.html.
I'm on a Mac and hope to get this stuff working in Xcode but for now I'm finding that bypassing Xcode makes things easier to understand.
1. Yes. But gnatmake does other things that make does not. For example, gnatmake determines all of the source dependencies so that, for example, to compile a main program that uses lots of other packages (modules or units), one has to only mention the main program source file in the gmatmake line. This works because Ada does not allow "uses propagation," requiring all "with" clauses ("uses" in Pascal) in every source file. Each compilation produces two output files, a .o file and a .ali text file (Ada Library Information) which contains the dependency information and a bunch of other stuff. gnatmake calls gcc as necessary, then gnatbind and gnatlink in turn. I think that you can do all of this using the usual gcc tools as well. I suspect that gnatmake probably does use the usual gcc tools. It looks like some of the switches are common to both. For example, gnat -c compiles only.
2. The GNAT compilation model has an extra step, performed by gnatbind, the binder. This step makes sure that there are no inconsistent versions about to be linked and looks at the .ali files; this consistency check is required by the rules of Ada. If files are out of date, they are recompiled. If all goes well, a new Ada source file is created which calls elaboration procs and then contains the original main program. This new "meta main" file is then compiled to make the object file for the main program. It is normally deleted afterwards. (NOTE that a -C switch compiles this "meta" main program in C rather than Ada. I'm not sure that I understand that.) The -n option is used when the main program is written in another language (no main program in Ada). Binder-generated filenames start with b~.
3. gnatlink is then called to build the executable using the object file from the gnatbind main process as well as other .o files for other units. There is an option to specify of the gcc linker, so that seems to imply that the default linker is the gcc one (and that is ld??). gnatlink can be called with only the last of the .ali files generated by gnatbind, which is why myadaprogram.ali does not appear in the gnatlink line, above.
You can make each of the three steps explicit, but gnatmake does it all for you. For example, the three-step process for a hello world program looks like this: 1. Compile the program with: gcc -c hello.adb 2. Bind the program with: gnatbind hello.ali 3. Link the program with: gnatlink hello.ali In this case, it is interesting to look at the .ali files and the binder-generated main program source.
Here is the output which is made with -v added to each of the gnatxxxx commands:
GNATMAKE 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc. "myadapackage.ali" being checked ... -> "myadapackage.ali" missing. gcc -c myadapackage.adb End of compilation
GNATMAKE 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc. "myadaprogram.ali" being checked ... -> "myadaprogram.ali" missing. gcc -c myadaprogram.adb "myadapackage.ali" being checked ... End of compilation
GNATBIND 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc.
Binding: myadapackage.ali Binding: myadaprogram.ali
No errors
GNATLINK 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1996-2002 Free Software Foundation, Inc. gcc -c -gnatA -gnatWb -gnatiw -fPIC -gnatws b~myadaprogram.adb /usr/bin/gcc b~myadaprogram.o pascalcallsada.o ./myadapackage.o ./ myadaprogram.o /Developer/Pascal/gpc344d2/lib/gcc/powerpc-apple- darwin8/3.4.4/libgpc.a -o mypascalprogram -L./ -L/usr/lib/ada/ /usr/ lib/ada/libgnat.a
And here is the output from the same commands run immediately again, without deleting any files made the first time:
GNATMAKE 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc. "myadapackage.ali" being checked ... End of compilation gnatmake: objects up to date.
GNATMAKE 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc. "myadaprogram.ali" being checked ... "myadapackage.ali" being checked ... End of compilation gnatmake: objects up to date.
GNATBIND 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc.
Binding: myadapackage.ali Binding: myadaprogram.ali
No errors
GNATLINK 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1996-2002 Free Software Foundation, Inc. gcc -c -gnatA -gnatWb -gnatiw -fPIC -gnatws b~myadaprogram.adb /usr/bin/gcc b~myadaprogram.o pascalcallsada.o ./myadapackage.o ./ myadaprogram.o /Developer/Pascal/gpc344d2/lib/gcc/powerpc-apple- darwin8/3.4.4/libgpc.a -o mypascalprogram -L./ -L/usr/lib/ada/ /usr/ lib/ada/libgnat.a
lanceboyle@qwest.net wrote:
Adriaan van Os wrote:
lanceboyle@qwest.net wrote:
(This post is related to two earlier posts by me, "Linking Ada to Pascal" and 'Where is documentation for "new argument to _p_initialize (@)" PCStrings.')
I've had some success here. The following two files (Pascal main program) and compile commands work.
Good to hear so.
<snip>
<Compile commands> gpc -c pascalcallsada.pas gnatmake -c myadapackage.adb gnatmake -c myadaprogram.adb gnatbind -n myadapackage.ali myadaprogram.ali gnatlink myadaprogram.ali pascalcallsada.o `gpc -print-file-name=libgpc.a` \ -o mypascalprogram
Without any knowledge of Ada, I am trying to understand what exactly happens here, so I have the following questions.
- gnatmake is the command to use to compile a .adb file into a .o
file ? 2. what does gnatbind do ? is it possible to add -v to see what exactly it does ? 3. same question for gnatlink. I assume it calls ld, adding Ada and OS runtime stuff ?
With this information it may be possible to add Ada support to gp, the gpc make/build utility (especially since the main program is Pascal in this example).
I've been dabbling with Ada for a while but only recently decided to try to get serious about it. In my case, that also means using tons of Pascal code that I don't want to re-write. So I'm having to learn a bit about stuff that I never bothered with before. This a way to say that I'm just a little ways into Ada and the GNAT (GNU Ada) build system etc. so please be wary of my answers. Also, I don't know C well.
Useful references include "GNAT User's Guide for Unix Platforms" at http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gnat_ug_unx/index.html#Top and "The Big Online Book of Linux Ada Programming" at http://www.oopweb.com/Ada/Documents/AdaLinux/VolumeFrames.html?/Ada/ Documents/AdaLinux/Volume/12.html.
I'm on a Mac and hope to get this stuff working in Xcode but for now I'm finding that bypassing Xcode makes things easier to understand.
Xcode can use a Makefile-based project (called an "External target" in Xcode), so using Xcode shouldn't be a problem. This is what the GPC Xcode Kit for Mac OS X does. Then you can mix Pascal/Ada with C/C++/ObjC/ObjC++ (not to mention Assembly and Fortran).
- Yes. But gnatmake does other things that make does not. For
example, gnatmake determines all of the source dependencies so that, for example, to compile a main program that uses lots of other packages (modules or units), one has to only mention the main program source file in the gmatmake line. This works because Ada does not allow "uses propagation," requiring all "with" clauses ("uses" in Pascal) in every source file. Each compilation produces two output files, a .o file and a .ali text file (Ada Library Information) which contains the dependency information and a bunch of other stuff. gnatmake calls gcc as necessary, then gnatbind and gnatlink in turn. I think that you can do all of this using the usual gcc tools as well. I suspect that gnatmake probably does use the usual gcc tools. It looks like some of the switches are common to both. For example, gnat -c compiles only.
- The GNAT compilation model has an extra step, performed by
gnatbind, the binder. This step makes sure that there are no inconsistent versions about to be linked and looks at the .ali files; this consistency check is required by the rules of Ada. If files are out of date, they are recompiled. If all goes well, a new Ada source file is created which calls elaboration procs and then contains the original main program. This new "meta main" file is then compiled to make the object file for the main program. It is normally deleted afterwards. (NOTE that a -C switch compiles this "meta" main program in C rather than Ada. I'm not sure that I understand that.) The -n option is used when the main program is written in another language (no main program in Ada). Binder-generated filenames start with b~.
GPC has a make/build utility named "gp", comparable to what you describe here for gnatmake/gnatbind. The "b~" convention is remarkable (the tilde character is also the home directory in pathnames, at least it is on Mac OS X).
- gnatlink is then called to build the executable using the object
file from the gnatbind main process as well as other .o files for other units. There is an option to specify of the gcc linker, so that seems to imply that the default linker is the gcc one (and that is ld??).
The linker is specified by the compiler's spec file/built-in specs. For gpc/gcc, it is usually "ld", either directly or through "collect2".
gnatlink can be called with only the last of the .ali files generated by gnatbind, which is why myadaprogram.ali does not appear in the gnatlink line, above.
You can make each of the three steps explicit, but gnatmake does it all for you. For example, the three-step process for a hello world program looks like this:
- Compile the program with: gcc -c hello.adb
- Bind the program with: gnatbind hello.ali
- Link the program with: gnatlink hello.ali
In this case, it is interesting to look at the .ali files and the binder-generated main program source.
Here is the output which is made with -v added to each of the gnatxxxx commands:
GNATMAKE 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc. "myadapackage.ali" being checked ... -> "myadapackage.ali" missing. gcc -c myadapackage.adb End of compilation
GNATMAKE 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc. "myadaprogram.ali" being checked ... -> "myadaprogram.ali" missing. gcc -c myadaprogram.adb "myadapackage.ali" being checked ... End of compilation
GNATBIND 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc.
Binding: myadapackage.ali Binding: myadaprogram.ali
No errors
GNATLINK 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1996-2002 Free Software Foundation, Inc. gcc -c -gnatA -gnatWb -gnatiw -fPIC -gnatws b~myadaprogram.adb /usr/bin/gcc b~myadaprogram.o pascalcallsada.o ./myadapackage.o ./myadaprogram.o /Developer/Pascal/gpc344d2/lib/gcc/powerpc-apple-darwin8/3.4.4/ libgpc.a -o mypascalprogram -L./ -L/usr/lib/ada/ /usr/lib/ada/libgnat.a
And here is the output from the same commands run immediately again, without deleting any files made the first time:
GNATMAKE 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc. "myadapackage.ali" being checked ... End of compilation gnatmake: objects up to date.
GNATMAKE 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc. "myadaprogram.ali" being checked ... "myadapackage.ali" being checked ... End of compilation gnatmake: objects up to date.
GNATBIND 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1995-2002 Free Software Foundation, Inc.
Binding: myadapackage.ali Binding: myadaprogram.ali
No errors
GNATLINK 3.3 20040913 (GNAT for Mac OS X build 1650) Copyright 1996-2002 Free Software Foundation, Inc. gcc -c -gnatA -gnatWb -gnatiw -fPIC -gnatws b~myadaprogram.adb /usr/bin/gcc b~myadaprogram.o pascalcallsada.o ./myadapackage.o ./myadaprogram.o /Developer/Pascal/gpc344d2/lib/gcc/powerpc-apple-darwin8/3.4.4/ libgpc.a -o mypascalprogram -L./ -L/usr/lib/ada/ /usr/lib/ada/libgnat.a
I see, here the linker is called through gcc. Looks quite straightforward, except that Ada has .ali files, just as gpc has .gpi and .gpd files. Thanks for the info.
Regards
Adriaan van Os