1

I'm working in a C project that has a call to ld in its build system like this:

ld --allow-multiple-definition --architecture mips -EB --relocatable a.o b.o c.o -o mylib.a a.o b.o c.o

But I've ran into a problem with the size of this command line (around 32 thousand chars with all the object files needed - and using cygwin) so I started to study a few modifications to it. One of them was to remove the second referecens to the same objects. Like this:

ld --allow-multiple-definition --architecture mips -EB --relocatable a.o b.o c.o -o mylib.a

However, this broke things down. I get lots and lots of undefined references all over the place.

Why did this happen? What is the difference between both calls? I'm reading ld's docs but so far no good.

BONUS

If you are lucky enough, your ld version might have the --start-group objs.o --end-group option to take care of things like that.

ivarec
  • 2,542
  • 2
  • 34
  • 57

1 Answers1

0

In general, if a library X depends on symbols defined in library Y, then X should appear ahead of Y in the list of libraries supplied to ld. It looks like you can work around this by supplying the names of your object files twice: this way, each pair of {X, Y} will also appear in the list as {Y, X}, and will link regardless of the intra-object dependencies. Sometimes you have cyclic references; then you must put an object on the ld's list twice.

Typically, you just play around with the ordering until you get it right. However, it does not look like it's possible with your 32-K command line. I read here that lorder and tsort can assist you in determining the right order automatically, but I cannot say if it's right or wrong, because I never used these tools.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523