1

I am developing an Open Source library and would have a headers-only library as dependency for it. This dependency will only be used in a single cpp file and thus not exposed via our libraries' headers.

Considering the following setup of an application:

OurLib/
  - includes <headerOnlyLib.h>, but does not expose this via headers (cpp only)
Application/
  - links to OurLib (either statically or dynamically)
  - includes <headerOnlyLib.h>

What problems can occur due to this setup? What if the application and the library use a different version of the headers-only library? Can there be conflicts? Will there be noticable code duplication?

And finally: Would there be an advantage in this context, if the headerOnlyLib instead was a dynamically or statically linked library?

Ident
  • 1,184
  • 11
  • 25
  • 1
    You may break ODR, and so have ill formed program. – Jarod42 May 16 '16 at 21:46
  • @Jarod42 , you say I "may" break it, if you added an explanation in which cases it would be broken (I assume if using non-inline, non-templated functions in the header-only library), then that would be an answer. But I am actually more interested in the case what happens if all functions are inline/templated, will there just be code duplication? May function implementations from an older header-only lib replace those of the newer one or vice-versa? – Ident May 17 '16 at 07:02
  • My first `may` should be removed. `inline` functions should be identical across all translation units. By "chance", you may have expected behavior. – Jarod42 May 17 '16 at 07:53
  • @jarod42, this seems to disagree with you: http://stackoverflow.com/a/4193698/3144964 , specifically it says that ODR is not broken if the functions are inline (Afaik the same applies to templated functions). Am I misunderstanding something about the linked answer? – Ident May 17 '16 at 18:58
  • It is ok if functions are `static inline`, as there is only one definition in that case, else definition should have same sequence of token. – Jarod42 May 17 '16 at 19:41

1 Answers1

1

Can there be conflicts?
...

Application/
      - links to OurLib (either statically or dynamically)
      - includes <headerOnlyLib.h> <<<<<<<<<<<<

What's marked out actually makes the model unsafe regarding the ODR rule applied.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • 1
    Isn't that the case ONLY if the library does not inline its functions or has template functions? Every proper header-only library does one of these for its functions. – Ident May 17 '16 at 06:58