Re: strange linking problem



In article <1114703379.735008.294480@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
nicolasbock@xxxxxxxxx wrote:

> Thanks Richard, I didn't know that. I usually use C, and since strings
> don't exist there I sort of assumed that to be similar in f90.

Fortran arrays of characters are pretty direct analogues to those of C.
In fact, it is sometimes more convenient to use arrays of characters
instead of strings when interfacing to C. But many character operations
in Fortran are more "naturally" done with character strings instead of
arrays. So most commonly, you'll see character strings instead of
character arrays in Fortran (like your example was using) unless there
are special circumstances.

> As far as I know, the linker goes through the object
> files and looks for unsatisfied references to functions and variables.
> Then it looks through the libraries and tries to satisfy those
> references by linking code from the libraries into the executable. If
> that's correct, then I don't understand how the linker does not either
> 1) find a reference to "test", link that in from the library and
> everyone's happy, or 2) see that "test" is not satisfied and give me an
> error. The fact that it does not complain suggests that the linker
> indeed is linking something into the executable from the library. But
> apparently something that does not contain the literal string that I
> assigned to "test".
>
> Could someone explain this to me?

I'll try. For procedures (both functions and subroutines), you are
right, but variables are different. For a procedure, things are
relatively simple (in this regard). The linker sees 2 kinds of things:
there are references to a procedure and there is a separate thing is the
procedure itself. If you have references with no corresponding
procedure, that is an error.

For data, however, it is possible to have multiple references to a data
area, with nothing that actually is uniquely the data area itself. This
is typical of non-initialized data areas. All that the linker sees is
that there should be a data area of a certain size and a certain name.
If something defines the area, then fine, that definition gets used. But
if nothing otherwise defines the data area, the linker will allocate an
an appropriate chunk of memory. This is not an error, and indeed is
quite typical for COMMON blocks.

I forget all the right terminology, but the "references" that the linker
sees for the variable "test" here are probably of this type, where you
won't get an error for a lack of other definition. The linker doesn't
tend to look in libraries for this kind of reference.

As alluded to by others, this used to be quite a widespread problem with
COMMON in f77 and earlier days. Modules are less prone to the problem,
but it can still happen (only when the modules have no referenced
procedures).

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
.



Relevant Pages

  • Re: strange linking problem
    ... I usually use C, and since strings ... the linker goes through the object ... files and looks for unsatisfied references to functions and variables. ... references by linking code from the libraries into the executable. ...
    (comp.lang.fortran)
  • Re: PIC Assembler.
    ... Imagine the simplest linker case. ... The assembler is ... these notes and modify this initially blank sheet. ... bytes and writes these as type strings into the OBJ file. ...
    (sci.electronics.basics)
  • Re: Home brew Z80 CP/M computer
    ... nice pile of assemblers and linkers. ... But it doesn't say what the SLR tools do with it. ... The thing that I absolutely _LOVED_ about the SLR tools was how well they dealt with external references. ... Reading between the lines, it was easy enough to figure out that Steve had defined a stack machine to do the address calculations, and embedded that into the linker. ...
    (comp.os.cpm)
  • Re: Im a stupid blond :( Please help me!!!
    ... > in a program to be left out of the external references table. ... Well for one the linker that comes with Microsoft Visual Studio 6 (not ... It's the loader's job to adjust ... > get the entire object file that contains that function linked in. ...
    (comp.lang.cpp)
  • Re: PIC Assembler.
    ... Imagine the simplest linker case. ... The assembler is ... these notes and modify this initially blank sheet. ... bytes and writes these as type strings into the OBJ file. ...
    (sci.electronics.basics)