Cannot use div operator in shared libraries
--=-=-
Hi,
Attached are to files to reproduce the error:
1) lib.c
2) dl_test.c
compile them with:
$ gcc -c lib.c $ ld -shared -o lib.so lib.o -lc $ cc dl_test.c -o dl_test -ldl $ cc dl_test.c -o dl_test2 -ldl ./lib.so
And test the result with
$ ./dl_test ./dl_test: error in loading shared libraries: ./lib.so: undefined symbol: __divdi3 $ ./dl_test2 13/5 = 2 2
Also '$ ld -shared -o lib.so lib.o -lc -Bsymbol' gives:
lib.o: In function `my_div':lib.o(.text+0x92): undefined reference to `__divdi3'
I am using turbolinux 0505.
Greetings
Christoph
--=-=-Content-Disposition: attachment; filename=lib.c
int my_div (int a, int b) {
int c;
c = a/b;
printf ("%d/%d = %d\n",a,b,c);
return c;
}
--=-=-Content-Disposition: attachment; filename=dl_test.c
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle;
int (*my_div)(int,int);
char *error;
handle = dlopen ("./lib.so", RTLD_LAZY);
if (!handle) {
fputs (dlerror(), stderr);
exit(1);
}
my_div = dlsym(handle, "my_div");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
} printf ("%d\n", (*my_div)(13,5));
dlclose(handle);
}
--=-=-=--
Christoph Rohland <[email protected]> writes:
|> Hi, |> |> Attached are to files to reproduce the error: |> |> 1) lib.c |> 2) dl_test.c |> |> compile them with: |> |> $ gcc -c lib.c |> $ ld -shared -o lib.so lib.o -lc
Don't call ld directly, use gcc instead.
Signature · 4 lines
Andreas Schwab "And now for something SuSE Labs completely different." [email protected] SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg