pcb-rnd knowledge pool

 

Lesstif/motif link failure + solution

motif by Tibor 'Igor2' Palinkas on 2017-09-10

Tags: dev, lesstif, motif, link, linking, order

node source

 

 

Abstract: Explain why lesstif/motif linking failed on some system and what the solution was to the tricky linking problem.

  Imported from the mailing list archives.

As of r11396, the lesstif HID should work on every system, with both lesstif and motif.

The long standing bug was a rather tricky one to figure. I never experienced it on my main systems but only one box while other users/developers consistently reported it. I thought it was a motif version problem, maybe something changed recently and others use a too new or too old version compared to my system.

Then I started to work on the attribute dialog upgrade and for some of the lesstif code I decided to set up a smallish test bench in work/ to try out ideas without having to compile and run pcb-rnd. And the minimal "hello world" test program immediately produced the same runtime error. I went on and copied the official test programs from motif and lesstif, and boom, the same error!

That's when I started to investigate the build parameters. It turned out the order of linking must be -lXm _before_ -lXt. If the order is wrong, there is no link time error, but the misleading runtime error.

And the difference between my systems and everyone else's? Opengl. I don't have it, so my link list had lesstif libs before gtk libs and within the lesstif lib link set the order is -lXm -lXt. With opengl, -lXt got on the list with opengl libs, way before lesstif, that's how we ended up with "-lXt <a_lot_of_other_stuff> -lXm -lXt", from which the second -lXt got removed as redundant.

Solution: this is a very special case. I've been coding C on various UNIX systems since about 1999, and never seen a link order causing such runtime error. Nevertheless, we may later on have other link order problems which would cause linking error, so I decided to go for a generic/proper solution. I've added a new feature in scconfig so that two items in a list can be reordered to meet a specific requirement. It does that by minimal change to the list, e.g. moving the out-of-order item only, right before (or after) the target word. The two lines that got added to src/Makefile.in:


# Lesstif requires that -lXm is before -lXt or else there is a runtime BadWindow
order /local/pcb/LDFLAGS {-lXm} {before} {-lXt}

This moves -lXm to right before -lXt if both are present on LDFLAGS and are in the wrong order.