This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

dlsym() does not return local symbol address


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

According to my interpretation, the program:

#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>

int local_sym(void)
{
	printf("Hello!\n");
	return 0;
}

int main()
{
	int (*sym)(void);
	void *h;

	h = dlopen(NULL,RTLD_NOW|RTLD_GLOBAL);
	if(h != NULL)
	{
		sym = dlsym(h,"local_sym");
		if(sym == NULL)
			printf("DL error: %s\n",dlerror());
		else
		{
			printf("Got it!\n");
			sym();
		}
		dlclose(h);
	}
	return 0;
}

should print:
Got it!
Hello!

but it prints:
DL error: ./t: undefined symbol: local_sym

I use glibc-2.3.3, Gentoo ebuild sys-libs/glibc-2.3.3.20040420, Linux
version 2.6.13-gentoo-r5.

The same program works well if I lookup "printf", for example.

Is this a bug? Or is it my interpretation of "man dlsym"?

Thanks!

- --
==============         +----------------------------------------------+
Martin Gadbois         | "Windows might take you from 0 to 60 faster, |
S/W Developer          |  but to go to 100 you need Unix."            |
Colubris Networks Inc. +----------------------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFZhtO9Y3/iTTCEDkRAhqOAJ4+39qSyHhjx/kct1ZgU+ldGmzz+gCgybaz
n9VxA6j1pVecMZVHqbDaZnI=
=yJaQ
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]