dlopen() and -pg flag

Lev Walkin vlm at netli.com
Wed Dec 3 02:22:59 PST 2003


-pg on your system implies static linking. dlopen() is not available in
statically linked binaries on FreeBSD and many other systems.

Consider building your binary dynamic by making sure there is a dynamic
version of libc with profiling support (something like /usr/lib/libc_p.so).

Otherwise, there seems to be no obvious way to do it.

Sergey Lyubka wrote:
> Below is a little snipper that tries to dlopen(argv[1]).
> It works fine until it is compiled with profiling support, -pg flag.
> 
> Compiled with -pg, dlopen() reports "Service unavailable".
> 
> How to fix that ?
> 
> -sergey
> 
> 
> 
> #include <dlfcn.h>
> #include <stdlib.h>
> #include <stdio.h>
> 
> int main(int argc, char *argv[])
> {
> 	void *handle, *sym;
> 
> 	if (argc > 1) {
> 		handle = dlopen(argv[1], RTLD_NOW);
> 		if (handle == NULL) {
> 			fprintf(stderr, "dlopen: %s\n", dlerror());
> 		} else {
> 			fprintf(stderr, "handle: %p\n", handle);
> 			if (argc > 2) {
> 				sym = dlsym(handle, argv[2]);
> 				fprintf(stderr, "%s: %p\n", argv[2], sym);
> 			}
> 		}
> 	}
> 
> 	return (EXIT_SUCCESS);
> }
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"


-- 
Lev Walkin
vlm at netli.com



More information about the freebsd-hackers mailing list