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

Link test runner executable into dll? #226

Closed
DaanDeMeyer opened this issue Apr 19, 2019 · 2 comments
Closed

Link test runner executable into dll? #226

DaanDeMeyer opened this issue Apr 19, 2019 · 2 comments

Comments

@DaanDeMeyer
Copy link
Contributor

When using DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL, I linked an executable containing the test runner implementation into a shared library containing the tests but when running the executable no tests are registered. Is this a supported use case?

I'm compiling with fvisibility=hidden if that makes a difference.

Executable source code + cmake:

external/doctest/main.cpp:

#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
add_executable(tests)

target_compile_features(tests PRIVATE cxx_std_11)
target_include_directories(tests PUBLIC external/doctest)
set_target_properties(tests PROPERTIES
  ENABLE_EXPORTS ON
)

target_sources(tests PRIVATE external/doctest/main.cpp)

test.cpp:

#define DOCTEST_IMPLEMENTATION_IN_DLL
#include <doctest.h>

...
add_library(mylib test.cpp)
target_link_libraries(mylib PRIVATE tests)
@onqtam
Copy link
Member

onqtam commented Apr 19, 2019

well such a scenario should be supported, but is the library necessary to the executable at all or is it only full of tests? Tests are self-registered upon startup but perhaps the entire library isn't necessary for the executable - try explicitly referencing a function in the executable which is defined in the dynamic library. If nothing defined in the library is explicitly referenced by the executable then the linker will optimize the library out - self-registering code in the library doesn't count... this is a common problem with static libraries and object files too.

Doctest will work fine even if you explicitly load the dll as a plugin using LoadLibrary btw...

@DaanDeMeyer
Copy link
Contributor Author

I got it working, had a few typos that caused problems. I also had to export and reference a function to get it to work. Thanks for the quick response.

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