Skip to content
This repository has been archived by the owner on Apr 14, 2019. It is now read-only.

Minimal example to accompany doctest question/issue

Notifications You must be signed in to change notification settings

bsamseth/doctest-linking-issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example Repo Acompanying onqtam/doctest/issues/224

Desired functionallity:

  • Library has tests written directely in the source
  • Possible to link a standalone executable to the library, without any doctest-related code

Now, if the library includes the doctest.h header, an executable simply using the library fails to link due to missing symbols for doctest. Building the test runner works just fine, but it seems that defining a separate main function without any doctest mentions causes the failiure.

Current behaviour:

> cmake . -Bbuild
-- The CXX compiler identification is GNU 8.2.0
... (finishes without any issues)

> cmake --build build
Scanning dependencies of target lib
[ 20%] Building CXX object CMakeFiles/lib.dir/lib.cpp.o
[ 20%] Built target lib
Scanning dependencies of target exec
[ 40%] Building CXX object CMakeFiles/exec.dir/exec.cpp.o
[ 60%] Linking CXX executable exec
Undefined symbols for architecture x86_64:
  "doctest::detail::setTestSuite(doctest::detail::TestSuite const&)", referenced from:
      __static_initialization_and_destruction_0(int, int) in lib.cpp.o
  "doctest::detail::TestSuite::TestSuite()", referenced from:
      __static_initialization_and_destruction_0(int, int) in lib.cpp.o
  "doctest::detail::TestSuite::~TestSuite()", referenced from:
      __static_initialization_and_destruction_0(int, int) in lib.cpp.o
  "doctest::detail::TestSuite::operator*(char const*)", referenced from:
      __static_initialization_and_destruction_0(int, int) in lib.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [exec] Error 1
make[1]: *** [CMakeFiles/exec.dir/all] Error 2
make: *** [all] Error 2

Or directly with g++:

> g++ -std=c++11 -Iexternal/doctest/doctest lib.cpp testrunner.cpp  # Works just fine.
> g++ -std=c++11 -Iexternal/doctest/doctest lib.cpp exec.cpp   # Fails as above.

About

Minimal example to accompany doctest question/issue

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published