comp.lang.ada
 help / color / mirror / Atom feed
* GprBuild and linker options
@ 2011-07-18 12:39 Felix Krause
  2011-07-18 20:32 ` Simon Wright
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Felix Krause @ 2011-07-18 12:39 UTC (permalink / raw)


I need GprBuild to use a custom linker option (in this case, for linking against an OSX framework). So I include this in my project file:

package Linker is
   for Linker_Options use ("-framework OpenCL", "-v");
end Linker;

When I try to build this project, this is the output I get at linking phase, which fails:

/usr/local/gnat/bin/gcc [...] -framework OpenCL -v [...]
[...]
COLLECT_GCC_OPTIONS=[...] '-framework OpenCL' '-v' [...]
 /usr/local/gnat/libexec/gcc/x86_64-apple-darwin10.2.0/4.5.3/collect2 [...]

After that, I get a list of undefined symbols. This is due to "-framework OpenCL" not being given to the collect2 call. I have no idea what COMPILE_GCC_OPTIONS does, but I noticed my switch being listed there. Now when I copypaste the above call to /usr/local/gnat/bin/gcc into my shell and execute it there, my switch isn't listed in COLLECT_GCC_OPTIONS anymore, but instead is given to the collect2 call, and everything links correctly.

Now of course, I want the build to work directly without having to copy commands to the shell. One thing I tried is splitting the switch into two strings:

for Linker_Options use ("-framework", "OpenCL", "-v");

The linking phase now executes the following:

/usr/local/gnat/bin/gcc [...] -framework /users/felix/projects/libs/openclada//OpenCL -v [...]

This obviously results in an error because this framework can't be found. I searched in the GprBuild user's guide for some hint on what causes this behavior, but I didn't find anything. Can anyone tell me how to either make the GprBuild execution with "-framework OpenCL" work like when I execute it in the shell, or prevent GprBuild from prepending the working path to "OpenCL" when passing two strings to Linker_Options?

Thanks.
Felix



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

* Re: GprBuild and linker options
  2011-07-18 12:39 GprBuild and linker options Felix Krause
@ 2011-07-18 20:32 ` Simon Wright
  2011-07-18 22:51   ` Felix Krause
  2011-07-19  5:59 ` anon
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Simon Wright @ 2011-07-18 20:32 UTC (permalink / raw)


Felix Krause <fordprefect86@googlemail.com> writes:

> I need GprBuild to use a custom linker option (in this case, for linking against an OSX framework). So I include this in my project file:
>
> package Linker is
>    for Linker_Options use ("-framework OpenCL", "-v");
> end Linker;
[...]
> /usr/local/gnat/bin/gcc [...] -framework /users/felix/projects/libs/openclada//OpenCL -v [...]
>
> This obviously results in an error because this framework can't be
> found. I searched in the GprBuild user's guide for some hint on what
> causes this behavior, but I didn't find anything. Can anyone tell me
> how to either make the GprBuild execution with "-framework OpenCL"
> work like when I execute it in the shell, or prevent GprBuild from
> prepending the working path to "OpenCL" when passing two strings to
> Linker_Options?

As a possible quick fix, could you try ths with gnatmake? (not of course
if it's a mixed-language project)

Although you'd have thought gprbuild & gnatmake would use the same logic
they are often out of step.



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

* Re: GprBuild and linker options
  2011-07-18 20:32 ` Simon Wright
@ 2011-07-18 22:51   ` Felix Krause
  0 siblings, 0 replies; 8+ messages in thread
From: Felix Krause @ 2011-07-18 22:51 UTC (permalink / raw)


> As a possible quick fix, could you try ths with gnatmake? (not of course
> if it's a mixed-language project)
> 
> Although you'd have thought gprbuild & gnatmake would use the same logic
> they are often out of step.

I just tried both variants with gnatmake, it behaves exactly the same.



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

* Re: GprBuild and linker options
  2011-07-18 12:39 GprBuild and linker options Felix Krause
  2011-07-18 20:32 ` Simon Wright
@ 2011-07-19  5:59 ` anon
  2011-07-19  8:20 ` Stephen Leake
  2011-07-19  9:14 ` Alex R. Mosteo
  3 siblings, 0 replies; 8+ messages in thread
From: anon @ 2011-07-19  5:59 UTC (permalink / raw)


try adding "-largs <linker options>" to the end of the command line

example:
   GprBuild  <normal options> -largs --Link=ld    


In <30764c54-0e96-4394-9a5c-d742adbc5344@glegroupsg2000goo.googlegroups.com>, Felix Krause <fordprefect86@googlemail.com> writes:
>I need GprBuild to use a custom linker option (in this case, for linking ag=
>ainst an OSX framework). So I include this in my project file:
>
>package Linker is
>   for Linker_Options use ("-framework OpenCL", "-v");
>end Linker;
>
>When I try to build this project, this is the output I get at linking phase=
>, which fails:
>
>/usr/local/gnat/bin/gcc [...] -framework OpenCL -v [...]
>[...]
>COLLECT_GCC_OPTIONS=3D[...] '-framework OpenCL' '-v' [...]
> /usr/local/gnat/libexec/gcc/x86_64-apple-darwin10.2.0/4.5.3/collect2 [...]
>
>After that, I get a list of undefined symbols. This is due to "-framework O=
>penCL" not being given to the collect2 call. I have no idea what COMPILE_GC=
>C_OPTIONS does, but I noticed my switch being listed there. Now when I copy=
>paste the above call to /usr/local/gnat/bin/gcc into my shell and execute i=
>t there, my switch isn't listed in COLLECT_GCC_OPTIONS anymore, but instead=
> is given to the collect2 call, and everything links correctly.
>
>Now of course, I want the build to work directly without having to copy com=
>mands to the shell. One thing I tried is splitting the switch into two stri=
>ngs:
>
>for Linker_Options use ("-framework", "OpenCL", "-v");
>
>The linking phase now executes the following:
>
>/usr/local/gnat/bin/gcc [...] -framework /users/felix/projects/libs/opencla=
>da//OpenCL -v [...]
>
>This obviously results in an error because this framework can't be found. I=
> searched in the GprBuild user's guide for some hint on what causes this be=
>havior, but I didn't find anything. Can anyone tell me how to either make t=
>he GprBuild execution with "-framework OpenCL" work like when I execute it =
>in the shell, or prevent GprBuild from prepending the working path to "Open=
>CL" when passing two strings to Linker_Options?
>
>Thanks.
>Felix




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

* Re: GprBuild and linker options
  2011-07-18 12:39 GprBuild and linker options Felix Krause
  2011-07-18 20:32 ` Simon Wright
  2011-07-19  5:59 ` anon
@ 2011-07-19  8:20 ` Stephen Leake
  2011-07-19 21:05   ` Felix Krause
  2011-07-19  9:14 ` Alex R. Mosteo
  3 siblings, 1 reply; 8+ messages in thread
From: Stephen Leake @ 2011-07-19  8:20 UTC (permalink / raw)


Felix Krause <fordprefect86@googlemail.com> writes:

> I need GprBuild to use a custom linker option (in this case, for linking against an OSX framework). So I include this in my project file:
>
> package Linker is
>    for Linker_Options use ("-framework OpenCL", "-v");
> end Linker;

As you have seen, this treats "-framework OpenCL" as a single option
string, which is not what your shell does.

> One thing I tried is splitting the switch into two strings:
>
> for Linker_Options use ("-framework", "OpenCL", "-v");
>
> The linking phase now executes the following:
>
> /usr/local/gnat/bin/gcc [...] -framework
> /users/felix/projects/libs/openclada//OpenCL -v [...]

Apparently gprbuild is treating each item in Linker_Options that does
not start with "-" as a library file; it searches for that file in the
search path, and provides the full path when found.

Which is not what you want.

> This obviously results in an error because this framework can't be
> found. I searched in the GprBuild user's guide for some hint on what
> causes this behavior, but I didn't find anything. 

The user's guide is woefully inadequate.

> Can anyone tell me how to either make the GprBuild execution with
> "-framework OpenCL" work like when I execute it in the shell, or
> prevent GprBuild from prepending the working path to "OpenCL" when
> passing two strings to Linker_Options?

Can you use "-framework=OpenCL"?

In the gcc manual, there is this:

`-Xlinker OPTION'
     Pass OPTION as an option to the linker.  You can use this to
     supply system-specific linker options which GCC does not know how
     to recognize.

     If you want to pass an option that takes an argument, you must use
     `-Xlinker' twice, once for the option and once for the argument.
     For example, to pass `-assert definitions', you must write
     `-Xlinker -assert -Xlinker definitions'.  It does not work to write
     `-Xlinker "-assert definitions"', because this passes the entire
     string as a single argument, which is not what the linker expects.

`-Wl,OPTION'
     Pass OPTION as an option to the linker.  If OPTION contains
     commas, it is split into multiple options at the commas.

either of these might work.

-- 
-- Stephe



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

* Re: GprBuild and linker options
  2011-07-18 12:39 GprBuild and linker options Felix Krause
                   ` (2 preceding siblings ...)
  2011-07-19  8:20 ` Stephen Leake
@ 2011-07-19  9:14 ` Alex R. Mosteo
  3 siblings, 0 replies; 8+ messages in thread
From: Alex R. Mosteo @ 2011-07-19  9:14 UTC (permalink / raw)


Felix Krause wrote:

> I need GprBuild to use a custom linker option (in this case, for linking
> against an OSX framework). So I include this in my project file:
> 
> package Linker is
>    for Linker_Options use ("-framework OpenCL", "-v");
> end Linker;
> 
> When I try to build this project, this is the output I get at linking
> phase, which fails:
> 
> /usr/local/gnat/bin/gcc [...] -framework OpenCL -v [...]
> [...]
> COLLECT_GCC_OPTIONS=[...] '-framework OpenCL' '-v' [...]
>  /usr/local/gnat/libexec/gcc/x86_64-apple-darwin10.2.0/4.5.3/collect2
>  [...]
> 
> After that, I get a list of undefined symbols. This is due to "-framework
> OpenCL" not being given to the collect2 call. I have no idea what
> COMPILE_GCC_OPTIONS does, but I noticed my switch being listed there. Now
> when I copypaste the above call to /usr/local/gnat/bin/gcc into my shell
> and execute it there, my switch isn't listed in COLLECT_GCC_OPTIONS
> anymore, but instead is given to the collect2 call, and everything links
> correctly.
> 
> Now of course, I want the build to work directly without having to copy
> commands to the shell. One thing I tried is splitting the switch into two
> strings:
> 
> for Linker_Options use ("-framework", "OpenCL", "-v");
> 
> The linking phase now executes the following:
> 
> /usr/local/gnat/bin/gcc [...] -framework
> /users/felix/projects/libs/openclada//OpenCL -v [...]
> 
> This obviously results in an error because this framework can't be found.
> I searched in the GprBuild user's guide for some hint on what causes this
> behavior, but I didn't find anything. Can anyone tell me how to either
> make the GprBuild execution with "-framework OpenCL" work like when I
> execute it in the shell, or prevent GprBuild from prepending the working
> path to "OpenCL" when passing two strings to Linker_Options?

Since I don't see that you have solved this, here's an example from a 
project of mine, in case it gives any idea:

package Linker is

for Default_Switches ("Ada") use 
Linker'Default_Switches ("Ada") &
("-Lsrc/rtwmp/lib",
"-Wl,-Bstatic",  -- force static linking
"-lrt-wmp",
"-lrt",          --  rt is for system clock_gettime, used by rt-wmp
"-Wl,-Bdynamic", -- restore default dynamic linking needed by other libs
"");
 
--  This form works when the current open project is a descendant.
for Linker_Options use Linker'Linker_Options &
 ("-Lsrc/rtwmp/lib");

end Linker;

I'm using both Linker'Default_Switches and Linker_Options. There are subtle 
differences between them, but I couldn't say exactly what right now, nor I 
think I ever could pinpoint them in the manual. They're related to relative 
path interaction with projects that use other projects IIRC. Besides, they 
have changed over the GPL releases.

> Thanks.
> Felix




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

* Re: GprBuild and linker options
  2011-07-19  8:20 ` Stephen Leake
@ 2011-07-19 21:05   ` Felix Krause
  2011-07-20 12:19     ` Stephen Leake
  0 siblings, 1 reply; 8+ messages in thread
From: Felix Krause @ 2011-07-19 21:05 UTC (permalink / raw)


> Can you use "-framework=OpenCL"?

No.

> In the gcc manual, there is this:
> 
> `-Xlinker OPTION'
>      Pass OPTION as an option to the linker.  You can use this to
>      supply system-specific linker options which GCC does not know how
>      to recognize.
> 
>      If you want to pass an option that takes an argument, you must use
>      `-Xlinker' twice, once for the option and once for the argument.
>      For example, to pass `-assert definitions', you must write
>      `-Xlinker -assert -Xlinker definitions'.  It does not work to write
>      `-Xlinker "-assert definitions"', because this passes the entire
>      string as a single argument, which is not what the linker expects.
> 
> `-Wl,OPTION'
>      Pass OPTION as an option to the linker.  If OPTION contains
>      commas, it is split into multiple options at the commas.
> 
> either of these might work.

While "-Xlinker OPTION" still has the same problems as before (the working directory will be prepended to OPTION), "-Wl,OPTION" works, as follows:

for Linker_Options use ("-Wl,-framework,OpenCL");

Thanks a lot!



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

* Re: GprBuild and linker options
  2011-07-19 21:05   ` Felix Krause
@ 2011-07-20 12:19     ` Stephen Leake
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Leake @ 2011-07-20 12:19 UTC (permalink / raw)


Felix Krause <fordprefect86@googlemail.com> writes:

>> Can you use "-framework=OpenCL"?
>
> No.
>
>> In the gcc manual, there is this:
>> 
>> `-Xlinker OPTION'
>>      Pass OPTION as an option to the linker.  You can use this to
>>      supply system-specific linker options which GCC does not know how
>>      to recognize.
>> 
>>      If you want to pass an option that takes an argument, you must use
>>      `-Xlinker' twice, once for the option and once for the argument.
>>      For example, to pass `-assert definitions', you must write
>>      `-Xlinker -assert -Xlinker definitions'.  It does not work to write
>>      `-Xlinker "-assert definitions"', because this passes the entire
>>      string as a single argument, which is not what the linker expects.
>> 
>> `-Wl,OPTION'
>>      Pass OPTION as an option to the linker.  If OPTION contains
>>      commas, it is split into multiple options at the commas.
>> 
>> either of these might work.
>
> While "-Xlinker OPTION" still has the same problems as before (the working directory will be prepended to OPTION), "-Wl,OPTION" works, as follows:
>
> for Linker_Options use ("-Wl,-framework,OpenCL");
>
> Thanks a lot!

Glad this helped.

Now we just need to get the gcc manual improved to point out this
difference. Or maybe it is gprbuild that is adding that directory.

So much to do, so little time. Sigh.

-- 
-- Stephe



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

end of thread, other threads:[~2011-07-20 12:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-18 12:39 GprBuild and linker options Felix Krause
2011-07-18 20:32 ` Simon Wright
2011-07-18 22:51   ` Felix Krause
2011-07-19  5:59 ` anon
2011-07-19  8:20 ` Stephen Leake
2011-07-19 21:05   ` Felix Krause
2011-07-20 12:19     ` Stephen Leake
2011-07-19  9:14 ` 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