Re: linking issue - what am I doing wrong?

2016-03-25 Thread Swift Griggs


Some folks, who have had similar issues, asked what I ended up doing and 
if I'd post it. Here's the skinny:


I was doing this:

gcc -g -Wall -I/usr/pkg/include -I/usr/X11R7/include -lXm \
  -L/usr/pkg/lib -o hello hello.c

I switched it to this:

gcc -Wl,-rpath,/usr/pkg/lib -Wl,-rpath,/usr/X11R7/lib -g -Wall \
  -I/usr/pkg/include -I/usr/X11R7/include -lXm \
  -L/usr/pkg/lib -o hello hello.c

I guess that bakes in the library search path to your resulting binary. 
Very helpful, actually. I just never really knew this was an alternative 
to something like always having to set LD_LIBRARY_PATH, but since I saw 
other programs that managed to pull it off, I thought I'd ask. I'm glad I 
did. There are so many smart folks on this list.


Thanks,
  Swift


Re: linking issue - what am I doing wrong?

2016-03-25 Thread Gerard Lally
On Fri, 25 Mar 2016 15:50:36 -0600 (MDT)
Swift Griggs  wrote:
> 
> Some folks, who have had similar issues, asked what I ended up doing and if 
> I'd post it. Here's the skinny:
> 
> I was doing this:
> 
> gcc -g -Wall -I/usr/pkg/include -I/usr/X11R7/include -lXm \
>-L/usr/pkg/lib -o hello hello.c
> 
> I switched it to this:
> 
> gcc -Wl,-rpath,/usr/pkg/lib -Wl,-rpath,/usr/X11R7/lib -g -Wall \
>-I/usr/pkg/include -I/usr/X11R7/include -lXm \
>-L/usr/pkg/lib -o hello hello.c
> 
> I guess that bakes in the library search path to your resulting binary. Very 
> helpful, actually. I just never really knew this was an alternative to 
> something like always having to set LD_LIBRARY_PATH, but since I saw other 
> programs that managed to pull it off, I thought I'd ask. I'm glad I did. 
> There are so many smart folks on this list.

Thanks Swift. (I hit Reply instead of Reply-All, so the list never saw
my request. Sorry about that.)

-- 
Gerard Lally



Re: linking issue - what am I doing wrong?

2016-03-25 Thread Swift Griggs

On Fri, 25 Mar 2016, Rhialto wrote:
It looks like you need to give the runtime library path to the linker. 
See ld's -rpath option.


Yep. J. Hannken-Illjes sent me a note about the same issue and I was able 
to make it work.


Unfortunately different compilers have slightly different ways of 
specifying this (and passing it on to the linker). I think 
-Wl,-rpath,arg is a common variant.


Well, I'm glad I'm learning about this. I'm sure it'll be useful on NetBSD 
and other platforms that don't use something like ldconfig.


I have a rant somewhere about how this is better than a global 
system-wide search path such as used by lunix or freebsd, but I'd have 
to look it up :)


No sweat, brother, I have no dog in that fight. I'm just trying to make my 
simple little tutorial programs work. I used to be a lot better with C, 
and I've been striving lately to get better so I can participate in some 
projects I care about. I'm not surprised that I'm tripping over the linker 
after not writing any real C in 10 years.


I guess this is how pkgsrc has to compile a _lot_ of stuff. The syntax for 
GCC is a bit clumsy, but it works. Once it's compiled in, it pretty well 
stays working. So, at least there is that. I don't have to mess around 
with ldconfig et al. Learning this also helps me understand the 
differences between platforms.


-Swift



Re: linking issue - what am I doing wrong?

2016-03-25 Thread Rhialto
On Fri 25 Mar 2016 at 14:53:20 -0600, Swift Griggs wrote:
> Any ideas?

It looks like you need to give the runtime library path to the linker.
See ld's -rpath option.

Unfortunately different compilers have slightly different ways of
specifying this (and passing it on to the linker). I think
-Wl,-rpath,arg is a common variant.

I have a rant somewhere about how this is better than a global
system-wide search path such as used by lunix or freebsd, but I'd have
to look it up :)

> -Swift
-Olaf.
-- 
___ Olaf 'Rhialto' Seibert  -- The Doctor: No, 'eureka' is Greek for
\X/ rhialto/at/xs4all.nl-- 'this bath is too hot.'


signature.asc
Description: PGP signature