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


linking issue - what am I doing wrong?

2016-03-25 Thread Swift Griggs


I'm doing some tutorials on Motif. I'm really just getting started. I'm 
doing something ignorant while linking and I'm not sure what it is. What 
happens is that I'm able to get Motif and Xtoolkit linked to my little 
test program, but the program won't run unless LD_LIBRARY_PATH is set. Yet 
other programs linked to Motif run fine without even setting that env 
variable. Here's what it looks like (let me know if you care what's in my 
silly little program, I believe this to be my own problem with linking):


So, my fundamental question is: Why does ldd see that 'plan' is linked to 
Motif versus my silly hello program that can't. Understand that if I set 
LD_LIBRARY_PATH to include /usr/pkg/lib, everything works fine.


sgriggs@m83 ~/code/motif $ gcc -g -Wall -I/usr/pkg/include -I/usr/X11R7/include 
-lXm -L/usr/pkg/lib -o hello hello.c
sgriggs@m83 ~/code/motif $ unset LD_LIBRARY_PATH
sgriggs@m83 ~/code/motif $ ./hello
Shared object "libXm.so.4" not found
sgriggs@m83 ~/code/motif $ ldd hello
hello:
-lXm.4 => not found
-lgcc_s.1 => /usr/lib/libgcc_s.so.1
-lc.12 => /usr/lib/libc.so.12
-lXt.7 => not found
sgriggs@m83 ~/code/motif $ ldd /usr/pkg/bin/plan
/usr/pkg/bin/plan:
-lXm.4 => /usr/pkg/lib/libXm.so.4
-lXmu.7 => /usr/X11R7/lib/libXmu.so.7
-lXt.7 => /usr/X11R7/lib/libXt.so.7
-lX11.7 => /usr/X11R7/lib/libX11.so.7
-lxcb.2 => /usr/X11R7/lib/libxcb.so.2
-lXau.7 => /usr/X11R7/lib/libXau.so.7
-lgcc_s.1 => /usr/lib/libgcc_s.so.1
-lc.12 => /usr/lib/libc.so.12
-lXdmcp.7 => /usr/X11R7/lib/libXdmcp.so.7
-lSM.7 => /usr/X11R7/lib/libSM.so.7
-lICE.7 => /usr/X11R7/lib/libICE.so.7
-lXext.7 => /usr/X11R7/lib/libXext.so.7
-lXrender.2 => /usr/X11R7/lib/libXrender.so.2
-lXft.3 => /usr/X11R7/lib/libXft.so.3
-lfontconfig.2 => /usr/X11R7/lib/libfontconfig.so.2
-lexpat.2 => /usr/lib/libexpat.so.2
-lfreetype.17 => /usr/X11R7/lib/libfreetype.so.17
-lz.1 => /usr/lib/libz.so.1
-lbz2.1 => /usr/lib/libbz2.so.1
-lXrandr.3 => /usr/X11R7/lib/libXrandr.so.3
-ljpeg.9 => /usr/pkg/lib/libjpeg.so.9
-lpng16.16 => /usr/pkg/lib/libpng16.so.16
-lm.0 => /usr/lib/libm.so.0

Any ideas?

-Swift