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

dll example won't compile #371

Closed
s9w opened this issue May 15, 2020 · 2 comments
Closed

dll example won't compile #371

s9w opened this issue May 15, 2020 · 2 comments

Comments

@s9w
Copy link

s9w commented May 15, 2020

Description

I'm having quite some trouble getting doctest to work with a dll. My dll consists only of the code from executable_dll_and_plugin/dll.cpp with the latest doctest.h file. Compiling this with VS2019 yields:

1>------ Build started: Project: sandbox_lib, Configuration: Debug x64 ------
1>math.cpp
1>   Creating library C:\...\vs_solution\x64\Debug\sandbox_lib.lib and object C:\...\vs_solution\x64\Debug\sandbox_lib.exp
1>math.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct doctest::detail::TestSuite & __cdecl doctest::detail::TestSuite::operator*(char const *)" (__imp_??DTestSuite@detail@doctest@@QEAAAEAU012@PEBD@Z) referenced in function "void __cdecl `dynamic initializer for '_DOCTEST_ANON_VAR_0''(void)" (??__E_DOCTEST_ANON_VAR_0@@YAXXZ)
1>math.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl doctest::detail::TestCase::TestCase(void (__cdecl*)(void),char const *,unsigned int,struct doctest::detail::TestSuite const &,char const *,int)" (__imp_??0TestCase@detail@doctest@@QEAA@P6AXXZPEBDIAEBUTestSuite@12@1H@Z) referenced in function "void __cdecl `dynamic initializer for '_DOCTEST_ANON_VAR_3''(void)" (??__E_DOCTEST_ANON_VAR_3@@YAXXZ)
1>math.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct doctest::detail::TestCase & __cdecl doctest::detail::TestCase::operator*(char const *)" (__imp_??DTestCase@detail@doctest@@QEAAAEAU012@PEBD@Z) referenced in function "void __cdecl `dynamic initializer for '_DOCTEST_ANON_VAR_3''(void)" (??__E_DOCTEST_ANON_VAR_3@@YAXXZ)
1>math.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl doctest::detail::TestCase::~TestCase(void)" (__imp_??1TestCase@detail@doctest@@QEAA@XZ) referenced in function "void __cdecl `dynamic initializer for '_DOCTEST_ANON_VAR_3''(void)" (??__E_DOCTEST_ANON_VAR_3@@YAXXZ)
1>math.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl doctest::detail::regTest(struct doctest::detail::TestCase const &)" (__imp_?regTest@detail@doctest@@YAHAEBUTestCase@12@@Z) referenced in function "void __cdecl `dynamic initializer for '_DOCTEST_ANON_VAR_3''(void)" (??__E_DOCTEST_ANON_VAR_3@@YAXXZ)
1>math.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl doctest::detail::setTestSuite(struct doctest::detail::TestSuite const &)" (__imp_?setTestSuite@detail@doctest@@YAHAEBUTestSuite@12@@Z) referenced in function "void __cdecl `dynamic initializer for '_DOCTEST_ANON_VAR_0''(void)" (??__E_DOCTEST_ANON_VAR_0@@YAXXZ)
1>math.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct doctest::detail::TestSuite & __cdecl doctest_detail_test_suite_ns::getCurrentTestSuite(void)" (__imp_?getCurrentTestSuite@doctest_detail_test_suite_ns@@YAAEAUTestSuite@detail@doctest@@XZ) referenced in function "void __cdecl `dynamic initializer for '_DOCTEST_ANON_VAR_3''(void)" (??__E_DOCTEST_ANON_VAR_3@@YAXXZ)
1>C:\...\vs_solution\x64\Debug\sandbox_lib.dll : fatal error LNK1120: 7 unresolved externals
1>Done building project "sandbox_lib.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Which seems apparently to be the case because the definitions are hidden by macro magic.

Extra information

  • latest doctest.h
  • VS2019 16.4 or so
  • Win10

edit: seems to work if I chose static lib instead of dynamic in VS.

@onqtam
Copy link
Member

onqtam commented May 15, 2020

The reason is that the dll project links to the implementation where the test runner of doctest resides - have a look at the accompanying CMakeLists.txt file - every binary which uses doctest links to it - even the plugin which is loaded at runtime.

@s9w
Copy link
Author

s9w commented May 16, 2020

Oh, I had the feeling the example was somewhat more complex than it seems. Thanks!

@s9w s9w closed this as completed May 16, 2020
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