comp.lang.ada
 help / color / mirror / Atom feed
* interfacing with c object link gnatmake link problem
@ 2019-11-10 21:04 Alain De Vos
  2019-11-10 21:15 ` Simon Wright
  0 siblings, 1 reply; 5+ messages in thread
From: Alain De Vos @ 2019-11-10 21:04 UTC (permalink / raw)


I try to interface to a c library.
The docs,
https://learn.adacore.com/courses/intro-to-ada/chapters/interfacing_with_c.html

How to inform gnatmake that it should link to mylibrary.o ?

I solve it currently by calling gnatlink explicitly after running gnatmake ,
but maybe there is a nicer solution.
% gnatlink mytest.ali ./maaltwee.o     


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

* Re: interfacing with c object link gnatmake link problem
  2019-11-10 21:04 interfacing with c object link gnatmake link problem Alain De Vos
@ 2019-11-10 21:15 ` Simon Wright
  2019-11-10 22:39   ` Niklas Holsti
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Wright @ 2019-11-10 21:15 UTC (permalink / raw)


Alain De Vos <devosalain71@gmail.com> writes:

> I try to interface to a c library.
> The docs,
> https://learn.adacore.com/courses/intro-to-ada/chapters/interfacing_with_c.html
>
> How to inform gnatmake that it should link to mylibrary.o ?
>
> I solve it currently by calling gnatlink explicitly after running gnatmake ,
> but maybe there is a nicer solution.
> % gnatlink mytest.ali ./maaltwee.o     

% gnatmake mytest.adb -largs maaltwee.o

(-largs is followed by arguments to be passed to the linker)


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

* Re: interfacing with c object link gnatmake link problem
  2019-11-10 21:15 ` Simon Wright
@ 2019-11-10 22:39   ` Niklas Holsti
  2019-11-11 14:17     ` Shark8
  2019-11-11 15:32     ` Simon Wright
  0 siblings, 2 replies; 5+ messages in thread
From: Niklas Holsti @ 2019-11-10 22:39 UTC (permalink / raw)


On 2019-11-10 23:15, Simon Wright wrote:
> Alain De Vos <devosalain71@gmail.com> writes:
> 
>> I try to interface to a c library.
>> The docs,
>> https://learn.adacore.com/courses/intro-to-ada/chapters/interfacing_with_c.html
>>
>> How to inform gnatmake that it should link to mylibrary.o ?
>>
>> I solve it currently by calling gnatlink explicitly after running gnatmake ,
>> but maybe there is a nicer solution.
>> % gnatlink mytest.ali ./maaltwee.o
> 
> % gnatmake mytest.adb -largs maaltwee.o
> 
> (-largs is followed by arguments to be passed to the linker)

My habit is to add

    pragma Linker_Options ("mylibrary.o");

to the Ada source file that imports the C functions. Then there is no 
need to add options to the gnatmake command.

--
Niklas Holsti
niklas holsti tidorum fi
       .      @       .


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

* Re: interfacing with c object link gnatmake link problem
  2019-11-10 22:39   ` Niklas Holsti
@ 2019-11-11 14:17     ` Shark8
  2019-11-11 15:32     ` Simon Wright
  1 sibling, 0 replies; 5+ messages in thread
From: Shark8 @ 2019-11-11 14:17 UTC (permalink / raw)


On Sunday, November 10, 2019 at 3:39:34 PM UTC-7, Niklas Holsti wrote:
> 
> My habit is to add
> 
>     pragma Linker_Options ("mylibrary.o");
> 
> to the Ada source file that imports the C functions. Then there is no 
> need to add options to the gnatmake command.

That is very good advice.
And since it's language-defined it should be pretty portable across compilers.


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

* Re: interfacing with c object link gnatmake link problem
  2019-11-10 22:39   ` Niklas Holsti
  2019-11-11 14:17     ` Shark8
@ 2019-11-11 15:32     ` Simon Wright
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Wright @ 2019-11-11 15:32 UTC (permalink / raw)


Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

> On 2019-11-10 23:15, Simon Wright wrote:
>> Alain De Vos <devosalain71@gmail.com> writes:
>>
>>> I try to interface to a c library.
[...]
>> % gnatmake mytest.adb -largs maaltwee.o
>>
>> (-largs is followed by arguments to be passed to the linker)
>
> My habit is to add
>
>    pragma Linker_Options ("mylibrary.o");
>
> to the Ada source file that imports the C functions. Then there is no
> need to add options to the gnatmake command.

When it's not a small demo/test program, my habit is to write a gprbuild
project file. Or maybe a makefile.

It won't worry me, but what if the object file turns out to be
mylibrary.obj? Much easier to change these sorts of OS-dependent things
outside Ada.


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

end of thread, other threads:[~2019-11-11 15:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-10 21:04 interfacing with c object link gnatmake link problem Alain De Vos
2019-11-10 21:15 ` Simon Wright
2019-11-10 22:39   ` Niklas Holsti
2019-11-11 14:17     ` Shark8
2019-11-11 15:32     ` Simon Wright

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