linker errors because external code is header-files-only



 DEVELOP > c-Plus-Plus > linker errors because external code is header-files-only

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Markus Dehmann"
Date: 07 Dec 2007 08:51:40 AM
Object: linker errors because external code is header-files-only
What to do if an external library is header-files-only (but you have
to use it), and you get lots of linker errors?
You will necessarily get linker errors "multiple definition of ..." if
you try to separate interface from implementation in your own code.
The external-library symbols will first be defined in one .o file and
then again in the next one that includes the same implementation-heavy
header.
Is there any way to avoid the linker errors, or do I have to give up
and also put everything in header files myself (resulting in eternal
compilation times etc)?
Thanks!
Markus
.

User: "Victor Bazarov"

Title: Re: linker errors because external code is header-files-only 07 Dec 2007 08:56:34 AM
Markus Dehmann wrote:

What to do if an external library is header-files-only (but you have
to use it), and you get lots of linker errors?

What kind of linker errors?

You will necessarily get linker errors "multiple definition of ..." if
you try to separate interface from implementation in your own code.

Huh?

The external-library symbols will first be defined in one .o file and
then again in the next one that includes the same implementation-heavy
header.

Apparently the external library doesn't define their functions 'inline'
if they are all implementations (definitions) and live in headers that
you include in more than one translation unit.

Is there any way to avoid the linker errors, or do I have to give up
and also put everything in header files myself (resulting in eternal
compilation times etc)?

No, don't put everything in headers. You have several options. One,
you could talk to the library creators trying to convince them to fix
the code. Two, you could extract all the declarations from their
headers, create new headers and use those and include *their* headers
in only one of your translation units. Three, you could change their
headers so that every definition is also declared 'inline', which will
not change the inlining, it will only shut the linker up.
Come back and tell us what you found suitable.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.
User: "Markus Dehmann"

Title: Re: linker errors because external code is header-files-only 07 Dec 2007 10:30:07 AM
On Dec 7, 9:56 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:

Markus Dehmann wrote:

What to do if an external library is header-files-only (but you have
to use it), and you get lots of linker errors?


What kind of linker errors?

You will necessarily get linker errors "multiple definition of ..." if
you try to separate interface from implementation in your own code.


Huh?

The external-library symbols will first be defined in one .o file and
then again in the next one that includes the same implementation-heavy
header.


Apparently the external library doesn't define their functions 'inline'
if they are all implementations (definitions) and live in headers that
you include in more than one translation unit.

Is there any way to avoid the linker errors, or do I have to give up
and also put everything in header files myself (resulting in eternal
compilation times etc)?


No, don't put everything in headers. You have several options. One,
you could talk to the library creators trying to convince them to fix
the code. Two, you could extract all the declarations from their
headers, create new headers and use those and include *their* headers
in only one of your translation units. Three, you could change their
headers so that every definition is also declared 'inline', which will
not change the inlining, it will only shut the linker up.

Come back and tell us what you found suitable.

Thanks for the suggestions! I was inexperienced enough not to know
much about the "inline" keyword (and apparently the library writers
were, too). I just added it to the offending functions in the library
code, and the linker is shut up. Maybe I can convince the library
creators to include them in the first place so that things won't break
when I have to upgrade to their next version.
Markus
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER