How to resolve multiple declaration of same variable in two different libraries.

V

vasudev.v

Hi All,

I have one program, it links to two libraries. There is a
variable with a same name in two different libraries. Compiler gives
multiple declaration of same variable error.

Please let me know how to resolve this error.

Thanks in Advance.

Regards,
Vasu
 
K

Kenny McCormack

Hi All,

I have one program, it links to two libraries. There is a
variable with a same name in two different libraries. Compiler gives
multiple declaration of same variable error.

Allow me to be the first to say this - and I say it from the deepness of my
heart, with all the kindness and love one has come to associate with the
helpful posts you get in this newsgroup:

Not portable. Can't discuss it here. Blah, blah, blah.
 
R

Richard Heathfield

(e-mail address removed) said:
Hi All,

I have one program, it links to two libraries. There is a
variable with a same name in two different libraries.
Ouch.

Compiler gives multiple declaration of same variable error.
Yup.

Please let me know how to resolve this error.

Drop one of the libraries. Sorry.

Alternatively, if you have source to one of the libraries, you could do a
mass search-and-replace operation (carefully!) on that object's name.

This is a compelling reason to minimise the use of file scope objects with
external linkage in libraries. If you really must use one, namespace it
effectively!

If you're IBM, call it something like: ibm_foolib_gNameGoesHere

If you're Hewlett-Packard, call it hp_foolib_gNameGoesHere

If you're an Open Source project, call it mih_foolib_gNameGoesHere where mih
is short for "my initials here" and should be replaced with your initials
(provided your name isn't Ian Barbara Millstone or Herbert Paxmeister).

If you're Microsoft, do whatever you damn well please, as usual, and the
rest of the world will either bend itself around you or ignore you
completely, as usual.
 
C

Chuck F.

I have one program, it links to two libraries. There is a
variable with a same name in two different libraries. Compiler
gives multiple declaration of same variable error.

Please let me know how to resolve this error.

Change the name in at least one library. Sounds like the libraries
are sloppily designed. Most well designed libraries attach unique
(hopefully) prefixes to all identifiers they expose.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
K

Keith Thompson

I have one program, it links to two libraries. There is a
variable with a same name in two different libraries. Compiler gives
multiple declaration of same variable error.

Please let me know how to resolve this error.

As others have pointed out, there's no direct way to resolve this in
standard C other than by changing the name in one of the libraries.

There *might* be some implementation-specific trick that could let you
get around this. I actually don't know of any such trick for any real
implementation, but it could exist. You might look into it (perhaps
by asking in an implementation-specific newsgroup). I'd recommend
following this path *only* if you're desperate and you can't change
either library; the resulting workaround is likely to be non-portable,
and could even break with the next release of whatever compiler you're
using.

You might consider splitting your program into two separate programs,
each one using just one of the libraries. Coordination and
communication between the two programs is likely to be tricky, and is
almost certain to be implementation-specific. This is also an
approach to be used only if you're desparate.

Whatever approach you take, you should complain bitterly to the
suppliers of both libraries. (If they're both from the same supplier,
complain *very* bitterly.)
 
J

jacob navia

(e-mail address removed) a écrit :
Hi All,

I have one program, it links to two libraries. There is a
variable with a same name in two different libraries. Compiler gives
multiple declaration of same variable error.

Please let me know how to resolve this error.

Thanks in Advance.

Regards,
Vasu

If you can't change the name in the library (no source) build one
library into a dynamically loaded library (DLL under windows,
or .so under linux/unix)

The DLL/so will hide the names from the rest of the software
but it will be able to use it. If your function is called
"foo", and exists in both libraries, make a function called
"Getfoo" that will access within the DLL/so the function/data

For instance if you have
Library1 exports foo
Library2 exports foo too.

Suppose foo is
void foo(void);

Make a DLL/so with Library1, and write

void CallFooFromLib1(void)
{
foo(); // will call foo from lib1
}

and then when you want to use in your code foo from lib1
rename your calls to CallFooFromLib1

jacob
 
A

August Karlstrom

I have one program, it links to two libraries. There is a
variable with a same name in two different libraries. Compiler gives
multiple declaration of same variable error.

What libraries are you using and what's the name of the clashing
variable? Just curious.


August
 
N

Nick Keighley

Kenny said:
Allow me to be the first to say this - and I say it from the deepness of my
heart, with all the kindness and love one has come to associate with the
helpful posts you get in this newsgroup:

Not portable. Can't discuss it here. Blah, blah, blah.

this is not correct
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top