Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inlining function defs #111

Closed
JaapAap opened this issue Dec 14, 2017 · 3 comments
Closed

inlining function defs #111

JaapAap opened this issue Dec 14, 2017 · 3 comments

Comments

@JaapAap
Copy link

JaapAap commented Dec 14, 2017

I am compiling the serialization library Cereal, which relies on doctest for its unit testing, using VS2017. I get loads of linking errors due to multiple inclusions of the doctest functions, for example, for the function definition of doctest::Approx::Approx(double) (and many others). Defining these as inline would resolve these. Is there a reason why this currently not the case?

@onqtam
Copy link
Member

onqtam commented Dec 14, 2017

Hi there - So glad I hear about another big project using doctest!

About your linker errors... doctest is a single header library with 2 parts - the top one is the interface, and the bottom one is the test runner implementation.

The definition of doctest::Approx::Approx(double) is in the implementation, which is conditionally compiled only if DOCTEST_CONFIG_IMPLEMENT is defined before including the framework header. That should be done in only one source file in the target binary (executable/shared object). You can think of the doctest header as 2 files - a .h and a .cpp which are concatenated in one file for easier distribution. That is also how all the dependencies are contained in only one translation unit of your project - all the #includes go into the implementation part. That is also the reason for the incredible compile times of doctest.

So if there are tons of linker errors - I would assume that there are multiple .cpp files which include the header and define that identifier within the same project (exe/dll/so) - and that is a broken setup - I'm not sure if it's because of the cmake files of Cereal, but this is not a problem in doctest per-se.

I cannot currently look into the doctest/cmake integration of cereal because I'm currently at work. If you manage to figure it out - let me know! Otherwise I'll check it out in a few hours/days...

@JaapAap
Copy link
Author

JaapAap commented Dec 14, 2017

Thanks for your reply and clear explanation - I used the VS2013 project file included by Cereal (not cmake), and indeed this is likely to be a broken setup (related to the way the unit tests within Cereal are organized), which I should be able to fix easily given the above.

@onqtam
Copy link
Member

onqtam commented Feb 6, 2018

I'm closing this since (I assume) it's not a problem with doctest.

@onqtam onqtam closed this as completed Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants