I have these two sources,
a.C:
#include <stdio.h>
void a() {
  printf("a called \n");
}

and b.C:
#include <stdio.h>
void foo();
typedef void (*VoidVoid)();
void b() {
  foo();
  /*
  VoidVoid f = foo;
  printf("%p\n",f); // disallow optimizing f away
  */
}

and compile them into a shared lib:
g++ -c -fPIC *.C
g++ -shared -fPIC -o ab.so a.o b.o

now I write an application that uses the lib ab.so, but not the
undefined function foo():

application.C:
void a();

int main() {
  a();
  return 0;
}

now I link the application:
g++ -o app application.o -Wl,-R.  ab.so 
-Wl,--unresolved-symbols=ignore-in-shared-libs

and run it:
./app

Everything works fine.
So far, so good.

Now I activate the commented lines in b.C, i.e., I take the address of foo().
Linking still works, but when I run app,
I get:
app: relocation error: ./ab.so: undefined symbol: _Z3foov

So, what is the difference between a call to foo() and taking its address,
from the linkers point of view?
Both statements are of course not executed when running app, as b() is never 
called.

This was done with gcc version 4.1.0, GNU ld version 2.17.

Any explanation?
-- 
        -ulrich lauther

[nosave]
----------------------------------------------------------------------------
Ulrich Lauther          ph: +49 89 636 48834 fx: ... 636 42284
Siemens CT SE 6         Internet: [EMAIL PROTECTED]

Siemens Aktiengesellschaft:
Vorsitzender des Aufsichtsrats: Heinrich v. Pierer;
Vorstand: Klaus Kleinfeld, Vorsitzender; Johannes Feldmayer, Joe Kaeser,
Rudi Lamprecht, Eduardo Montes, Juergen Radomski, Erich R. Reinhardt,
Hermann Requardt, Uriel J. Sharef, Klaus Wucherer
Sitz der Gesellschaft: Berlin und Muenchen
Registergericht: Berlin Charlottenburg, HRB 12300, Muenchen, HRB 6684
WEEE-Reg.-Nr. DE 23691322
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to