[Nelug] ld and unit testing in C

Martin Ward martin at gkc.org.uk
Tue Sep 25 11:58:28 UTC 2007


On Tuesday 25 Sep 2007 00:02, Oliver Burnett-Hall wrote:
> > Have you tried the option --unresolved-symbols=ignore-all
> > or --unresolved-symbols=ignore-in-object-files ?
>
> I'd missed that one in the ld man page, and it does let me run the
> linker successfully.  However it just means I now get errors at run time
> instead of link time:
>
> # ./check_ranges
>                                        ~/src/gnumeric/gnumeric/test/unit
> ./check_ranges: symbol lookup error: ./check_ranges: undefined symbol:
> gnm_app_prefs
>
> [gnm_app_prefs is a symbol referenced from ranges.o that I'm really not
> interested in]
>
> I really don't understand this stuff at all; the books I've got on C
> programming are all platform agnostic so don't tell you much about
> compiling and linking, and the docs I've found for gcc are either
> trivial or assume that you understand all this already.  Can anyone
> point me in the direction of something that might help me understand?

This works for me: I added a definition to one of the source files in
a program I am working on, like this:

void bar();

void
foo(i)
     int i;
{
  bar(i);
}

Here, foo() is never called, and bar() is not defined anywhere.

A normal link gave this error:

% gcc -o zzz *.o
pack.o: In function `foo':
pack.c:(.text+0xd): undefined reference to `bar'
collect2: ld returned 1 exit status

Adding the option makes the error go away:

% gcc -Xlinker --unresolved-symbols=ignore-in-object-files -o zzz *.o

And the resulting executable works.

gnm_app_prefs is a pointer, isn't it? Is it referenced in one of the functions
you call from ranges.c? Have you tries creating a dummy definition
for it (as a void pointer)?


-- 
			Martin

martin at gkc.org.uk http://www.cse.dmu.ac.uk/~mward/ Erdos number: 4
G.K.Chesterton web site: http://www.cse.dmu.ac.uk/~mward/gkc/




More information about the Nelug mailing list