* Ada file depends on C file
@ 2009-09-17 12:38 mockturtle
2009-09-17 13:07 ` Ludovic Brenta
2009-09-17 13:29 ` Dmitry A. Kazakov
0 siblings, 2 replies; 7+ messages in thread
From: mockturtle @ 2009-09-17 12:38 UTC (permalink / raw)
Dear all,
I have a question that I am afraid is awfully trivial, but I spent
half a morning without finding any answer.
My setup: I am working with GPS and I have an Ada procedure (say
Interface_to_Addr in foo.adb) that needs to call a small C function
(char *interface_to_ip (char*)) defined in interface_to_ip.c. So, in
my Ada code I wrote
function interface_to_ip(interf : chars_ptr) return chars_ptr;
pragma Import(C, interface_to_ip);
Everything compiles fine, but when it is time to link, the linker
complains (correctly) that it cannot find "interface_to_ip". The
problem is that the compiler does not know that interface_to_ip is in
interface_to_ip.c, or, in other words, it does not know that foo.adb
depends on interface_to_ip.c.
Currently I solved by adding the line
pragma Linker_Options("../../interface_to_ip.o");
and by compiling "by hand" interface_to_ip.c to interface_to_ip.o, but
this solution is *UGLY*.
Everything would be fine if I could tell to the compiler that foo.adb
depends on interface_to_ip.c, but I do not know how to do it. I
looked under the GPS "Project" menu, browsed the GNAT user & reference
manuals (although not in the deepest detail) and googled for a while,
but I could not find an answer.
Thank you in advance for your help.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada file depends on C file
2009-09-17 12:38 Ada file depends on C file mockturtle
@ 2009-09-17 13:07 ` Ludovic Brenta
2009-09-17 13:32 ` mockturtle
2009-09-17 13:29 ` Dmitry A. Kazakov
1 sibling, 1 reply; 7+ messages in thread
From: Ludovic Brenta @ 2009-09-17 13:07 UTC (permalink / raw)
mockturtle wrote on comp.lang.ada:
> Dear all,
> I have a question that I am afraid is awfully trivial, but I spent
> half a morning without finding any answer.
>
> My setup: I am working with GPS and I have an Ada procedure (say
> Interface_to_Addr in foo.adb) that needs to call a small C function
> (char *interface_to_ip (char*)) defined in interface_to_ip.c. So, in
> my Ada code I wrote
>
> function interface_to_ip(interf : chars_ptr) return chars_ptr;
> pragma Import(C, interface_to_ip);
>
> Everything compiles fine, but when it is time to link, the linker
> complains (correctly) that it cannot find "interface_to_ip". The
> problem is that the compiler does not know that interface_to_ip is in
> interface_to_ip.c, or, in other words, it does not know that foo.adb
> depends on interface_to_ip.c.
>
> Currently I solved by adding the line
>
> pragma Linker_Options("../../interface_to_ip.o");
>
> and by compiling "by hand" interface_to_ip.c to interface_to_ip.o, but
> this solution is *UGLY*.
>
> Everything would be fine if I could tell to the compiler that foo.adb
> depends on interface_to_ip.c, but I do not know how to do it. I
> looked under the GPS "Project" menu, browsed the GNAT user & reference
> manuals (although not in the deepest detail) and googled for a while,
> but I could not find an answer.
>
> Thank you in advance for your help.
I normally use a Makefile to compile in such situations but there are
two alternatives: gprmake and its successor, gprbuild. In GPS, you can
specify that your project is multi-language; this will cause it to
call the proper tool (instead of gnatmake, which is for Ada-only
projects). I cannot be more specific as I don't use GPS myself.
Hopefully the project manager interface in GPS should be intuitive
enough.
--
Ludovic Brenta.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada file depends on C file
2009-09-17 12:38 Ada file depends on C file mockturtle
2009-09-17 13:07 ` Ludovic Brenta
@ 2009-09-17 13:29 ` Dmitry A. Kazakov
1 sibling, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2009-09-17 13:29 UTC (permalink / raw)
On Thu, 17 Sep 2009 05:38:43 -0700 (PDT), mockturtle wrote:
> Dear all,
> I have a question that I am afraid is awfully trivial, but I spent
> half a morning without finding any answer.
>
> My setup: I am working with GPS and I have an Ada procedure (say
> Interface_to_Addr in foo.adb) that needs to call a small C function
> (char *interface_to_ip (char*)) defined in interface_to_ip.c. So, in
> my Ada code I wrote
>
> function interface_to_ip(interf : chars_ptr) return chars_ptr;
> pragma Import(C, interface_to_ip);
>
> Everything compiles fine, but when it is time to link, the linker
> complains (correctly) that it cannot find "interface_to_ip". The
> problem is that the compiler does not know that interface_to_ip is in
> interface_to_ip.c, or, in other words, it does not know that foo.adb
> depends on interface_to_ip.c.
>
> Currently I solved by adding the line
>
> pragma Linker_Options("../../interface_to_ip.o");
>
> and by compiling "by hand" interface_to_ip.c to interface_to_ip.o, but
> this solution is *UGLY*.
>
> Everything would be fine if I could tell to the compiler that foo.adb
> depends on interface_to_ip.c, but I do not know how to do it. I
> looked under the GPS "Project" menu, browsed the GNAT user & reference
> manuals (although not in the deepest detail) and googled for a while,
> but I could not find an answer.
The project file (*.gpr) has "package Linker". You can put linker options
there for example:
package Linker is
for Default_Switches ("ada")
use ("-g", "-lgmem", <...further options...>);
end Linker;
Alternatively, and probably better solution, would be to include the C
source into the project. AFAIK GPS supports C. In that case you should be
able to handle interface_to_ip.c exactly as you do Ada files.
BTW, never use GPS->Project->Edit Project Properties. Notepad is your
friend! (:-))
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada file depends on C file
2009-09-17 13:07 ` Ludovic Brenta
@ 2009-09-17 13:32 ` mockturtle
2009-09-17 14:49 ` Ludovic Brenta
0 siblings, 1 reply; 7+ messages in thread
From: mockturtle @ 2009-09-17 13:32 UTC (permalink / raw)
On Sep 17, 3:07 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> mockturtle wrote on comp.lang.ada:
>
>
>
>
>
> > Dear all,
> > I have a question that I am afraid is awfully trivial, but I spent
> > half a morning without finding any answer.
>
> > My setup: I am working with GPS and I have an Ada procedure (say
> > Interface_to_Addr in foo.adb) that needs to call a small C function
> > (char *interface_to_ip (char*)) defined in interface_to_ip.c. So, in
> > my Ada code I wrote
>
> > function interface_to_ip(interf : chars_ptr) return chars_ptr;
> > pragma Import(C, interface_to_ip);
>
> > Everything compiles fine, but when it is time to link, the linker
> > complains (correctly) that it cannot find "interface_to_ip". The
> > problem is that the compiler does not know that interface_to_ip is in
> > interface_to_ip.c, or, in other words, it does not know that foo.adb
> > depends on interface_to_ip.c.
>
> > Currently I solved by adding the line
>
> > pragma Linker_Options("../../interface_to_ip.o");
>
> > and by compiling "by hand" interface_to_ip.c to interface_to_ip.o, but
> > this solution is *UGLY*.
>
> > Everything would be fine if I could tell to the compiler that foo.adb
> > depends on interface_to_ip.c, but I do not know how to do it. I
> > looked under the GPS "Project" menu, browsed the GNAT user & reference
> > manuals (although not in the deepest detail) and googled for a while,
> > but I could not find an answer.
>
> > Thank you in advance for your help.
>
> I normally use a Makefile to compile in such situations but there are
> two alternatives: gprmake and its successor, gprbuild. In GPS, you can
> specify that your project is multi-language; this will cause it to
> call the proper tool (instead of gnatmake, which is for Ada-only
I did. If I open with an editor the .gpr file created by GPS I find
the line
for Languages use ("Ada", "C");
> projects). I cannot be more specific as I don't use GPS myself.
> Hopefully the project manager interface in GPS should be intuitive
> enough.
Unfortunately I was not able to find any way to "logically connect"
the two files.
I must say that I am maybe using an old version (GPS 4.0.2 from
Help->About), maybe this is easier in the current version. (For
several reasons,
I would avoid updating if possible)
>
> --
> Ludovic Brenta.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada file depends on C file
2009-09-17 13:32 ` mockturtle
@ 2009-09-17 14:49 ` Ludovic Brenta
2009-09-17 16:17 ` Dmitry A. Kazakov
0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Brenta @ 2009-09-17 14:49 UTC (permalink / raw)
mockturtle wrote on comp.lang.ada:
> On Sep 17, 3:07 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
>> I normally use a Makefile to compile in such situations but there are
>> two alternatives: gprmake and its successor, gprbuild. In GPS, you can
>> specify that your project is multi-language; this will cause it to
>> call the proper tool (instead of gnatmake, which is for Ada-only
>
> I did. If I open with an editor the .gpr file created by GPS I find
> the line
>
> for Languages use ("Ada", "C");
From memory, this is necessary but not sufficient; you also have to
tick a check box somewhere to tell GPS that your project file is multi-
language. This is confusing, I know, and I learned the hard way :)
--
Ludovic Brenta.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada file depends on C file
2009-09-17 14:49 ` Ludovic Brenta
@ 2009-09-17 16:17 ` Dmitry A. Kazakov
2009-09-17 17:35 ` mockturtle
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2009-09-17 16:17 UTC (permalink / raw)
On Thu, 17 Sep 2009 07:49:46 -0700 (PDT), Ludovic Brenta wrote:
> mockturtle wrote on comp.lang.ada:
>> On Sep 17, 3:07�pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
>>> I normally use a Makefile to compile in such situations but there are
>>> two alternatives: gprmake and its successor, gprbuild. In GPS, you can
>>> specify that your project is multi-language; this will cause it to
>>> call the proper tool (instead of gnatmake, which is for Ada-only
>>
>> I did. �If I open with an editor the .gpr file created by GPS I find
>> the line
>>
>> � �for Languages use ("Ada", "C");
>
> From memory, this is necessary but not sufficient; you also have to
> tick a check box somewhere to tell GPS that your project file is multi-
> language. This is confusing, I know, and I learned the hard way :)
Hmm, adding C files into the list of sources should suffice. For example,
the following works for me:
------- mixed.gpr
project Mixed is
for Languages use ("Ada", "C");
for Source_Dirs use (".");
for Source_Files use ("main.adb", "c.c");
for Main use ("main.adb");
end Mixed;
------ main.adb
with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C; use Interfaces.C;
procedure Main is
function C return Int;
pragma Import (C, C);
begin
Put_Line ("Value:" & Int'Image (C));
end Main;
------ c.c
int c (void)
{
return 123;
}
----------------------------------------------
This should compile under GPS and print
Value: 123
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada file depends on C file
2009-09-17 16:17 ` Dmitry A. Kazakov
@ 2009-09-17 17:35 ` mockturtle
0 siblings, 0 replies; 7+ messages in thread
From: mockturtle @ 2009-09-17 17:35 UTC (permalink / raw)
On Sep 17, 6:17 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Thu, 17 Sep 2009 07:49:46 -0700 (PDT), Ludovic Brenta wrote:
> > mockturtle wrote on comp.lang.ada:
> >> On Sep 17, 3:07 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> >>> I normally use a Makefile to compile in such situations but there are
> >>> two alternatives: gprmake and its successor, gprbuild. In GPS, you can
> >>> specify that your project is multi-language; this will cause it to
> >>> call the proper tool (instead of gnatmake, which is for Ada-only
>
> >> I did. If I open with an editor the .gpr file created by GPS I find
> >> the line
>
> >> for Languages use ("Ada", "C");
>
> > From memory, this is necessary but not sufficient; you also have to
> > tick a check box somewhere to tell GPS that your project file is multi-
> > language. This is confusing, I know, and I learned the hard way :)
>
> Hmm, adding C files into the list of sources should suffice. For example,
> the following works for me:
>
> ------- mixed.gpr
> project Mixed is
> for Languages use ("Ada", "C");
> for Source_Dirs use (".");
> for Source_Files use ("main.adb", "c.c");
> for Main use ("main.adb");
> end Mixed;
> ------ main.adb
> with Ada.Text_IO; use Ada.Text_IO;
> with Interfaces.C; use Interfaces.C;
>
> procedure Main is
> function C return Int;
> pragma Import (C, C);
> begin
> Put_Line ("Value:" & Int'Image (C));
> end Main;
> ------ c.c
> int c (void)
> {
> return 123;}
>
> ----------------------------------------------
> This should compile under GPS and print
>
> Value: 123
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de
Thank you to everyone for your help. I just discovered that it is
maybe a problem with the old GPS version: I moved the complete
"packet" to a computer with GPS 4.3.1 (20090114) and everything worked
without changing a bit. Hmmm... I am afraid that I will need to
update the older GPS.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-09-17 17:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-17 12:38 Ada file depends on C file mockturtle
2009-09-17 13:07 ` Ludovic Brenta
2009-09-17 13:32 ` mockturtle
2009-09-17 14:49 ` Ludovic Brenta
2009-09-17 16:17 ` Dmitry A. Kazakov
2009-09-17 17:35 ` mockturtle
2009-09-17 13:29 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox