-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
Linking issue for executables after including doctest in library #224
Comments
If you don't have a test runner implemented somewhere in a binary (.dll/.so/.dylib/.exe) you would get these linker errors - you can use DOCTEST_CONFIG_DISABLE but then why would you include doctest in the first place? You have tests somewhere, right? The link to the repository you provided is broken - repo seems nonexistent (or is perhaps private). |
Wow, made the repo private by mistake. Made it public now, hopefully that illuminates things better! Thanks for the quick response! |
@bsamseth seems like you will be writing tests in the library itself - otherwise why would you be including the header there. This is actually what doctest was built for! But... you will need to supply a test runner even for the This is the only way if you would want to compile the sources in the library just once (seems that is what you want to achieve with the object library). If you want no test runner in the executable then you would need to define When mixing doctest tests with production code it is assumed that for developer builds there will be a test runner in the production binary, but for final Release builds which will be shipped to customers Does this make sense? |
Yes, I wanted to write the tests within the library, as I really like that idea. I also want to avoid having to build the library once per exec., as it takes a while to build the entire thing. But I think I get it now. I was worried external users would have to add doctest defines in their code, but of course, the version they would be provided could define Thanks for the help. Really liking doctest so far, I'm thinking it'll be my goto going forward :) |
I'm trying to the exact same thing, but am unsure of how you solved it. Will anyone who depends on the library also have to do so in each and every executable? |
@midjji if the tests are always compiled in the library then yes, you will need a test runner linked in every final binary that uses your library. Is your library static? I assume so. You could also implement the test runner in the library itself and then users of the library (executables) will only need to create a You could also have a release configuration in which build your library with You can also have the test runner in a separate shared object by using There are plenty of options - depending on what you want to achieve. |
Just ran into this exact use case. It's unfortunate that I can't have (only) test cases in DLLs, and then use them from a production binary with no test runner. But I suppose this is a C++ limitation... |
Note
I suspect this is a simple oversight from my side, and is not belived to be a bug in doctest. This is more of a support question, and I appologise in advance for what probably is a simple fix.
Description
I have written some tests in my library, and successfully compile a test runner executable.
Now I want to make another executable which has nothing to do with tests, and simply uses functionality from the library. However, I cannot seem to get around a linking error which occurs as a result of including doctest in the library.
The error goes like this:
In short, how do I go about setting this up so that users (including myself) of my library can link against it without having to know about doctest?
Steps to reproduce
I've made a minimal example at this repository: https://github.com/bsamseth/doctest-linking-issue
Clone the repository, including submodules, then try the above commands.
Extra information
The text was updated successfully, but these errors were encountered: