Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sharing a variable across libraries

0 views
Skip to first unread message

guddu

unread,
Jun 28, 2008, 8:04:33 PM6/28/08
to
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 ??

Thanks and Regards,
Vishal
--
comp.lang.c.moderated - moderation address: cl...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.

Andrei Voropaev

unread,
Jul 4, 2008, 2:46:43 AM7/4/08
to
On 2008-06-29, guddu <vish...@gmail.com> wrote:
> 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 ??


Well, try to read some documents available in internet. Buy some
programming books. Ask someone. But please, don't state that something
is not possible simply because you didn't manage to get it working :)


--
Minds, like parachutes, function best when open

Paul D. DeRocco

unread,
Aug 7, 2008, 4:02:16 PM8/7/08
to
> "guddu" <vish...@gmail.com> wrote

>
> 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.

In general, C prohibits you from duplicating anything that takes memory,
whether it's a variable or a function, in more than one module. Some
toolchains let you create the equivalent of Fortran common blocks, and
indeed that facility is commonly used in C++ code for things like virtual
function tables, but it's outside the C paradigm, because it's impossible to
ensure that both definitions are the same.

However, it doesn't make much sense to me to have two libraries sharing one
header file. In general, a header file describes one collection of related
resources. And since a library is a container from which a linker can pull
in only the modules you actually need, you probably want to put the two
libraries together. Then, your problem goes away.

--

Ciao, Paul D. DeRocco
Paul mailto:pder...@ix.netcom.com

0 new messages