comp.lang.ada
 help / color / mirror / Atom feed
* GPS example fails to compile
@ 2006-06-21 20:43 Xcriber51
  2006-06-21 20:56 ` Pascal Obry
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Xcriber51 @ 2006-06-21 20:43 UTC (permalink / raw)


Hi

After finally deciding to dive into the world of a language that requires
you to write...

    function Get_It (n: Integer) return Integer;

..what you can say in C as...

    int get_it (int n);
    
..I have downloaded the much-touted GPS IDE. 

Have I pissed you off already? Ok, that was just to get your attention,
forget that.

Seriously, after installing the IDE, I went ahead with the first tutorial:
SDC (the simple calculator), under "C:\GPS\doc\gps\examples\demo" (with the
default Windows installation), defined by the project file "sdc.gpr".

When I reached the full compilation stage of the Tutorial, I got a nasty
failure: gnatmake stops at "matrix_binding.adb", telling me that a series
of binding functions have "undefined reference to" 'name-of-function'.

The functions are in a C file ("matrix_utils.c" and/or "matrix.h")
included in the project. 

But my question is this: As I was trying to figure out how Ada manages
binding with external language modules (in our case with C code), I saw
that it uses the following syntax:

    function Alloc (Rows, Columns : Integer) return Matrix_Type is
        function C_Alloc (Rows, Columns : short) return Matrix_Type;
        pragma Import (C, C_Alloc, "matrixAlloc");
    begin
        return C_Alloc (short (Rows), short (Columns));
    end Alloc;

Now as I gather from another example in this forum, this "Import" function
works like so:

    -- Based on our example
    pragma Import (
        Convention      => C,
        Entity          => C_Alloc,
        External_Name   => "matrixAlloc"
        );

That's fine, but how does the compiler know where the heck "matrixAlloc"
is? I can't see the actual C file where the "matrixAlloc" and similar
functions are located included or explicitly referred to in the
"matrix_binding.ads" file, either. 

I checked:

- the .GPR file - the project directories are listed there, but not the
actual external module names;

- the GPS help system (which has topic headings like
"Interfaces.C.Strings", although they don't lead to any help files - that
link refers to an .ADS file, for instance);

- "Ada Distilled", the Wikibook "Ada Programming", the site "AdaPower",
etc.

I just couldn't find something that actually explains this to me.

Obviously - by Eric Raymondian criteria -, I'm dumb.

Any patient soul out there to explain how the f--- Ada does binding with
an external language module? (Not the "pragma import" construct, dammit,
but how the whole thing comes together.)

Thanks, patient soul!


-- Ken

P.S. Oh, and by the way: Why doesn't the example compile? Is it because I
installed GPS on an XP system when it was a full moon?






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

* Re: GPS example fails to compile
  2006-06-21 20:43 GPS example fails to compile Xcriber51
@ 2006-06-21 20:56 ` Pascal Obry
  2006-06-21 21:16   ` Xcriber51
  2006-06-21 21:12 ` Gautier
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Pascal Obry @ 2006-06-21 20:56 UTC (permalink / raw)


Xcriber51 a �crit :

> P.S. Oh, and by the way: Why doesn't the example compile? Is it because I
> installed GPS on an XP system when it was a full moon?

Probably yes.

Yet you did not tell which compiler you are using nor the version of the
GPS you have installed.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: GPS example fails to compile
  2006-06-21 20:43 GPS example fails to compile Xcriber51
  2006-06-21 20:56 ` Pascal Obry
@ 2006-06-21 21:12 ` Gautier
  2006-06-22  5:00 ` Jeffrey R. Carter
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Gautier @ 2006-06-21 21:12 UTC (permalink / raw)


Xcriber51 wrote:
[...]
> Any patient soul out there to explain how the f---

Bless you!

 > Ada does binding with
> an external language module? (Not the "pragma import" construct, dammit,
> but how the whole thing comes together.)

This is done at the linker level, the usual way - I suppose you know 
how it works, since you are fluent in C...

> Thanks, patient soul!

If you want to see an example, there is a binding to OpenGL (a 
graphics library) on the link below. There are tons of pragma Import, 
and you can see how it works with the GNU (Windows, Linux) and the 
Microsoft linkers.
_____________________________________________________
GLOBE_3D -- http://www.mysunrise.ch/users/gdm/g3d.htm

NB: For a direct answer, e-mail address on the Web site!



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

* Re: GPS example fails to compile
  2006-06-21 20:56 ` Pascal Obry
@ 2006-06-21 21:16   ` Xcriber51
  0 siblings, 0 replies; 12+ messages in thread
From: Xcriber51 @ 2006-06-21 21:16 UTC (permalink / raw)


Sorry about that, Pascal. I downloaded and installed it just a few days
ago, so it's the latest version. On the About dialog, it says "GPS 3.0.0
(20050517). In the command console, "gnat" displays the date "(20050729)".


Hope these help.


-- Ken




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

* Re: GPS example fails to compile
  2006-06-21 20:43 GPS example fails to compile Xcriber51
  2006-06-21 20:56 ` Pascal Obry
  2006-06-21 21:12 ` Gautier
@ 2006-06-22  5:00 ` Jeffrey R. Carter
  2006-06-22 11:29 ` Stephen Leake
  2006-06-22 22:41 ` Simon Wright
  4 siblings, 0 replies; 12+ messages in thread
From: Jeffrey R. Carter @ 2006-06-22  5:00 UTC (permalink / raw)


Xcriber51 wrote:
> 
> Any patient soul out there to explain how the f--- Ada does binding with
> an external language module? (Not the "pragma import" construct, dammit,
> but how the whole thing comes together.)

When you import a subprogram from another language, you're going outside 
the Ada language, so the compiler can't help you. You've entered the 
realm of unchecked programming, where you're telling the compiler, 
"Trust me." (Of course, decades of experience with languages like C show 
that, for anything significant, we can't be trusted.)

At link time, you have to provide the linker with the implementation of 
the imported operation so your program can call it. Ada provides pragma 
Linker_Options for that. With gnatmake, you can use -largs to provide 
linker options, or use the project-file mechanism.

-- 
Jeff Carter
"To Err is human, to really screw up, you need C++!"
St�phane Richard
63



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

* Re: GPS example fails to compile
  2006-06-21 20:43 GPS example fails to compile Xcriber51
                   ` (2 preceding siblings ...)
  2006-06-22  5:00 ` Jeffrey R. Carter
@ 2006-06-22 11:29 ` Stephen Leake
  2006-06-22 22:41 ` Simon Wright
  4 siblings, 0 replies; 12+ messages in thread
From: Stephen Leake @ 2006-06-22 11:29 UTC (permalink / raw)


"Xcriber51" <xcriber@[OMITTED]> writes:

> After finally deciding to dive into the world of a language that requires
> you to write...
>
>     function Get_It (n: Integer) return Integer;
>
> ..what you can say in C as...
>
>     int get_it (int n);

Good move.

> ..I have downloaded the much-touted GPS IDE. 

Bad move. Stick with Emacs.

See http://fsw.gsfc.nasa.gov/gds/tools_install_windows.pdf
for complete installation instructions.

Have fun :).

-- 
-- Stephe



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

* Re: GPS example fails to compile
  2006-06-21 20:43 GPS example fails to compile Xcriber51
                   ` (3 preceding siblings ...)
  2006-06-22 11:29 ` Stephen Leake
@ 2006-06-22 22:41 ` Simon Wright
  2006-06-23  8:18   ` Ludovic Brenta
  4 siblings, 1 reply; 12+ messages in thread
From: Simon Wright @ 2006-06-22 22:41 UTC (permalink / raw)


"Xcriber51" <xcriber@[OMITTED]> writes:

> That's fine, but how does the compiler know where the heck "matrixAlloc"
> is? I can't see the actual C file where the "matrixAlloc" and similar
> functions are located included or explicitly referred to in the
> "matrix_binding.ads" file, either. 

Hmm, nor do I.

I know how to tell the linker to use the C .o's; Edit > Project
Properties > Switches > Ada Linker, at the bottom enter

  obj/matrix.o obj/matrix_utils.o

and I can compile the C sources (select the file and Build > Compile
File) but what I don't see is how to get GPS to do it for itself.

I have to admit to not reading the instructions, though.



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

* Re: GPS example fails to compile
  2006-06-22 22:41 ` Simon Wright
@ 2006-06-23  8:18   ` Ludovic Brenta
  2006-06-23 12:59     ` Alex R. Mosteo
  0 siblings, 1 reply; 12+ messages in thread
From: Ludovic Brenta @ 2006-06-23  8:18 UTC (permalink / raw)


Simon Wright a écrit :
> "Xcriber51" <xcriber@[OMITTED]> writes:
>
> > That's fine, but how does the compiler know where the heck "matrixAlloc"
> > is? I can't see the actual C file where the "matrixAlloc" and similar
> > functions are located included or explicitly referred to in the
> > "matrix_binding.ads" file, either.
>
> Hmm, nor do I.
>
> I know how to tell the linker to use the C .o's; Edit > Project
> Properties > Switches > Ada Linker, at the bottom enter
>
>   obj/matrix.o obj/matrix_utils.o
>
> and I can compile the C sources (select the file and Build > Compile
> File) but what I don't see is how to get GPS to do it for itself.
>
> I have to admit to not reading the instructions, though.

It's in the file scm.gpr: it says "for Languages use ("Ada", "C")" and
the source directories containing both C and Ada source files. It seems
that recent versions of gnatmake have built-in support for C as well as
Ada. I haven't looked any further though.

-- 
Ludovic Brenta.




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

* Re: GPS example fails to compile
  2006-06-23  8:18   ` Ludovic Brenta
@ 2006-06-23 12:59     ` Alex R. Mosteo
  2006-06-23 19:35       ` Xcriber51
  2006-06-25 20:41       ` Simon Wright
  0 siblings, 2 replies; 12+ messages in thread
From: Alex R. Mosteo @ 2006-06-23 12:59 UTC (permalink / raw)


Ludovic Brenta wrote:

> Simon Wright a �crit :
>> "Xcriber51" <xcriber@[OMITTED]> writes:
>>
>> > That's fine, but how does the compiler know where the heck
>> > "matrixAlloc" is? I can't see the actual C file where the "matrixAlloc"
>> > and similar functions are located included or explicitly referred to in
>> > the "matrix_binding.ads" file, either.
>>
>> Hmm, nor do I.
>>
>> I know how to tell the linker to use the C .o's; Edit > Project
>> Properties > Switches > Ada Linker, at the bottom enter
>>
>>   obj/matrix.o obj/matrix_utils.o
>>
>> and I can compile the C sources (select the file and Build > Compile
>> File) but what I don't see is how to get GPS to do it for itself.
>>
>> I have to admit to not reading the instructions, though.
> 
> It's in the file scm.gpr: it says "for Languages use ("Ada", "C")" and
> the source directories containing both C and Ada source files. It seems
> that recent versions of gnatmake have built-in support for C as well as
> Ada. I haven't looked any further though.

I use Ada plus C plus C++ ;) routinely. You tell the languages in the
project file as you say, and enable "multilanguage build" in GPS options. 

This, translated to command line dudes, means that instead of "gnatmake",
another tool is used: "gprmake". It will compile all C and C++ sources in
the project folders, create a library with them and link it in the final
executable (also the proper linker for C or C++ is called).

So, in short: use gprmake with your project files if you're using
multilanguage, or enable the corresponding option in GPS. 




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

* Re: GPS example fails to compile
  2006-06-23 12:59     ` Alex R. Mosteo
@ 2006-06-23 19:35       ` Xcriber51
  2006-06-25 20:41       ` Simon Wright
  1 sibling, 0 replies; 12+ messages in thread
From: Xcriber51 @ 2006-06-23 19:35 UTC (permalink / raw)


Alex: It turned out to be just a setting issue: 

Edit > Preferences > General | Multi language build: Enabled.

Ludovic: I had noticed the settings about the directories in the .GPR
file, but that still doesn't fully answer my question. The thing is, as
Simon mentions, this is probably done by the linker -- i.e. not specified
textually, but handled via compiler/linker magic.

(I was thinking maybe something like the IDL type specification files were
involved.)

Anyway, thank you, all of you patient souls.


-- Ken





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

* Re: GPS example fails to compile
  2006-06-23 12:59     ` Alex R. Mosteo
  2006-06-23 19:35       ` Xcriber51
@ 2006-06-25 20:41       ` Simon Wright
  2006-06-26  6:58         ` Alex R. Mosteo
  1 sibling, 1 reply; 12+ messages in thread
From: Simon Wright @ 2006-06-25 20:41 UTC (permalink / raw)


"Alex R. Mosteo" <devnull@mailinator.com> writes:

> I use Ada plus C plus C++ ;) routinely. You tell the languages in the
> project file as you say, and enable "multilanguage build" in GPS options.

So you do.

This is an example of help files that help you if you already know the
answer (or are prepared to read the whole thing in case it turns out
that there's an answer).

I was very much expecting to find this in the project options (ie the
GPR file), not in a general preferences section!



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

* Re: GPS example fails to compile
  2006-06-25 20:41       ` Simon Wright
@ 2006-06-26  6:58         ` Alex R. Mosteo
  0 siblings, 0 replies; 12+ messages in thread
From: Alex R. Mosteo @ 2006-06-26  6:58 UTC (permalink / raw)


Simon Wright wrote:

> "Alex R. Mosteo" <devnull@mailinator.com> writes:
> 
>> I use Ada plus C plus C++ ;) routinely. You tell the languages in the
>> project file as you say, and enable "multilanguage build" in GPS options.
> 
> So you do.
> 
> This is an example of help files that help you if you already know the
> answer (or are prepared to read the whole thing in case it turns out
> that there's an answer).
> 
> I was very much expecting to find this in the project options (ie the
> GPR file), not in a general preferences section!

I have also manifested a couple of times my surprise at it being not a
project option, or simply an autodetected thing if your project says that
you're using something else than Ada.

I guess there's some reason for it being like it is, but I ignore it.



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

end of thread, other threads:[~2006-06-26  6:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-21 20:43 GPS example fails to compile Xcriber51
2006-06-21 20:56 ` Pascal Obry
2006-06-21 21:16   ` Xcriber51
2006-06-21 21:12 ` Gautier
2006-06-22  5:00 ` Jeffrey R. Carter
2006-06-22 11:29 ` Stephen Leake
2006-06-22 22:41 ` Simon Wright
2006-06-23  8:18   ` Ludovic Brenta
2006-06-23 12:59     ` Alex R. Mosteo
2006-06-23 19:35       ` Xcriber51
2006-06-25 20:41       ` Simon Wright
2006-06-26  6:58         ` Alex R. Mosteo

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