Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 03 Dec 2003 02:23:18 -0800
From:      Lev Walkin <vlm@netli.com>
To:        Sergey Lyubka <devnull@uptsoft.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: dlopen() and -pg flag
Message-ID:  <3FCDB996.4090603@netli.com>
In-Reply-To: <20031203121658.A822@oasis.uptsoft.com>
References:  <20031203121658.A822@oasis.uptsoft.com>

next in thread | previous in thread | raw e-mail | index | archive | help

-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@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


-- 
Lev Walkin
vlm@netli.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3FCDB996.4090603>