Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: legend.msil.sps.mot.com: danield set sender to Daniel DOT Daboul AT motorola DOT com using -f Date: Wed, 19 Mar 2003 13:24:18 +0200 From: Daniel Daboul To: cygwin AT cygwin DOT com Subject: _init() and _fini() for dynamically loaded libraries? Message-ID: <20030319112418.GO24792@legend.msil.sps.mot.com> Mail-Followup-To: cygwin AT cygwin DOT com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.3i Does Cygwin support initialization and cleanup for libraries loaded dynamically via dlopen() in a way similar to Linux and Solaris? If yes, how can I get it to work? I attached a simple test case below, with comments telling how to compile/link. The output under cygwin is: calculating doubled in library: 2.468000 So it basically works, but neither _init() nor _fini() get executed. Under Solaris the output is: initializing calculating doubled in library: 2.468000 finishing (There I link with "ld -Bshareable mylib.o -o libmylib.dll" and "gcc -Wall -o caller caller.c -ldl".) Solaris declares _init and _fini in (actually returning int), which does not exists in my cygwin installation, but I'm not sure this is enough to conclude that it's unsupported. I didn't find help in the documentation or mail-archives. -- Daniel /* mylib.c gcc -Wall -c mylib.c gcc -shared -Wl,--export-all mylib.o -o libmylib.dll */ #include double dub(double in1) {printf("calculating\n");return 2*in1;} void _init() {printf("initializing\n");} void _fini() {printf("finishing\n");} /* caller.c gcc -Wall -o caller caller.c ./caller */ #include #include #include int main() { void *handle; double (*pdub)(double); char *error; handle = dlopen("./libmylib.dll",RTLD_LAZY); if(!handle) {fprintf(stderr,"%s\n",dlerror()); exit(1);} pdub =dlsym(handle,"dub"); if((error = dlerror())!=NULL) {fprintf(stderr,"%s\n",error); exit(1);} printf("doubled in library: %f\n",(*pdub)(1.234)); dlclose(handle); return 0; } -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/