trinity Normal compilation spits my ELF out fine but fails to run with ./program: Shared object "libXm.so.4" not found
For this, you have to add these linker flags to your compile cmd. line: -Wl,-rpath=/usr/X11R7/lib -Wl,-rpath=/usr/pkg/lib
because /usr/X11R7/lib
and /usr/pkg/lib
are not in the dynamic linker's default search path.
trinity Static compilation says the following:
This is a more complicated case. For static linking, you'll have to bring in every library object needed by the binary and its main libraries (except libc
) explicitly, and in dependency-order (Ie. if liba.a
requires objects in libb.a
, then you'll need to supply -la -lb
; the other way will fail with undefined references
errors).
It's a bit of a pain, all this, (you have to run ldd
on the binary/shared object, then lorder
and tsort
etc.--in the bad ol' days I recall having to add the same library twice to get all the dependencies resolved!) so here's a ready-made command line:
cc -static -I/usr/pkg/include -I/usr/X11R7/include -o motif motif.c \
-L/usr/pkg/lib -L/usr/X11R7/lib \
-lXm -lXmu -lXt -lSM -lICE -lXext -lpng16 -lz -lbz2 \
-lXft -lfontconfig -lfreetype -lexpat -lXrender -lX11 \
-lxcb -lXau -lXdmcp -lXrandr -ljpeg -lm