From gcc manual:
"It makes a difference where in the command you write this option; the linker searches processes libraries and object files in the order they are specified. Thus, `foo.o -lz bar.o' searches library `z' after file `foo.o' but before `bar.o'. If `bar.o' refers to functions in `z', those functions may not be loaded."
Got stucked by this stupid mistake for a long time.
So
$(CC) $(CFLAGS) weight.o -loolm -lmisc -ldstruct -o weight
works while
$(CC) $(CFLAGS) -loolm -lmisc -ldstruct weight.o -o weight
DOESN'T!!!
Conclusion: put main() obj first!
"It makes a difference where in the command you write this option; the linker searches processes libraries and object files in the order they are specified. Thus, `foo.o -lz bar.o' searches library `z' after file `foo.o' but before `bar.o'. If `bar.o' refers to functions in `z', those functions may not be loaded."
Got stucked by this stupid mistake for a long time.
So
$(CC) $(CFLAGS) weight.o -loolm -lmisc -ldstruct -o weight
works while
$(CC) $(CFLAGS) -loolm -lmisc -ldstruct weight.o -o weight
DOESN'T!!!
Conclusion: put main() obj first!
Comments