4

I use statically linked sqlite database and in order to compile every next version I sometimes have to do minor changes in the list of object files used. But sometimes the changes I have to make puzzles me. For example prior to version 3_6_10 this order

{$L 'Objs\is.OBJ'}
{$L 'Objs\mbisspc.OBJ'}

was ok, but starting 3_6_12 the linker said

unsatisfied forward or external declaration _isspace

but changing the order to

{$L 'Objs\mbisspc.OBJ'}
{$L 'Objs\is.OBJ'}

helped. As for the changes in sqlite, it really stopped to use c function isspace in 3_6_12 and started to use an internal equivalent so "isspace" keyword even don't appear inside the obj file.

So why does the order of linked object file with $L directive matter and where I can read more about this? I suppose it is something related to cross-usage of the listed obj files, but I will feel more safe if I understand what is going on

Thanks

Maksee
  • 2,311
  • 2
  • 24
  • 34

1 Answers1

4

Edit:

As of the comment by David Heffernan linking to his answer to this other question on linking .obj file in Delphi, I replaced linker by compiler, and added a the italic portion below:

C compilers use a multi-pass linker compiler that knows how to resolve forward and circular dependencies between .obj files.

Since the Delphi linker compiler is targeted at the Delphi language, and the Delphi language does not allow for that, the linker compiler does not allow for this either.

Pro: the linker compiler is much faster.

Con: you need to help the linker compiler a bit by placing the .obj files in the right order
, or by manually resolving the dependencies (see the above mentioned answer by David Heffernan) .

--jeroen

Community
  • 1
  • 1
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • 1
    So from what you said, I conclude that there might be a situation when Delphi 1-pass linker won't be able to link if the references are circular? – Maksee Jul 12 '10 at 12:56
  • @Maksee: I think that is indeed possible. I'm not sure if the Borland C++ Linker works around this in any way. – Jeroen Wiert Pluimers Jul 13 '10 at 14:44
  • @Jeroen since the C++ linker is linking C++, surely it would have to deal with circular references? – David Heffernan Jan 09 '11 at 15:37
  • @Jeroen I think you answer should actually refer to the compiler rather than the linker. Surely it's the compiler that is single pass. The linker has to be multi-pass. First pass to concatenate the objects and build the map. Second pass to fixup all the function addresses. – David Heffernan Jan 09 '11 at 19:07
  • @David: I think the fix-ups are done at link time. Barry Kelly or Danny Thorpe would be the guys with the ultimate answer for this :-) – Jeroen Wiert Pluimers Jan 10 '11 at 09:19
  • @Jeroen These issues are all at compile time; you can see that because the error is reported when compiling rather than linking. I have found that declaring the missing forward/external reference as an external procedure is enough to get the compile to succeed. I'm guessing that doing so tells the compiler to write a JMP/CALL that will be resolved at link fixup time. See http://http://stackoverflow.com/questions/4638186/error-while-linking-multiple-c-object-files-in-delphi-2007 – David Heffernan Jan 10 '11 at 09:24
  • @Jeroen @Maksee all this gives a way to get round any problems with circular references. – David Heffernan Jan 10 '11 at 09:25