guddu said:
Hi,
I have to share a variable across two libraries. These libraries are
build separately and share a common header file.
I had tried this earlier using extern variable. That didn't help.
Any ideas about this ??
If you must do this (rather than use parameter-passing, say), do it like
this:
/* commonheader.h */
#ifndef H_COMMONHEADER
#define H_COMMONHEADER 1
extern int shared_object; /* a declaration - include as appropriate */
/* + whatever else you feel appropriate in here */
#endif
/* firstlibsourcefile.c */
#include "commonheader.h"
int shared_object; /* ONE definition, here ONLY */
/* functions and stuff go here */
/* someotherlibsourcefile.c */
#include "commonheader.h" /* get the declaration */
/* Note the absence of a definition */
/* functions and stuff go here */
HTH. HAND.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999