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
Doctest is not able to compile on OSX #126
Comments
weird... I have an OSX build of doctest on travis with the same version of clang: I also tried your branch locally on Windows with VS 2017 and GCC 7.2 and its fine - seems like an OSX issue. Normally I try to resolve serious issues as fast as possible but currently I have no time to spare - I have to prepare 2 full lectures - after 10 days everything will be over and I'll be able to perhaps try this on a Mac - sorry for the inconvenience. One other note: doctest has REQUIRE asserts just like Catch - its not just CHECK that is available. |
@onqtam Thanks for the quick reply. I'll keep trying to fix this ... somehow. For now, I'm going to isolate this issue by remove all extraneous details and then see if the build works. Thanks for that note about the |
@onqtam Ok Update. I've created another repository in which I'm trying to use doctest on OSX, and ... it works fine! Now I have to figure out the difference between it and my repository. The repository is here: https://github.com/arnavb/osx-doctest |
Hi there, So I forked and played with your 2 repositories and here is what I tried:
My bet is that this is a toolchain issue - and it saddens me that such problems occur in 2018. I guess I'll have to investigate this further... |
@onqtam Hmmm... that's interesting. I've added a UPDATE: ANOTHER UPDATE: |
I added including a header should not result in fixing link errors............. I have exactly 0 pleasant memories of native development under OSX... Windows has the Anyway - I don't think I can spare more time on this for now - sorry. The |
@onqtam You're right. I added 😖 On a side note... I really want to thank you for all of your help with this issue! I know it must be hard to take time out of your busy schedule as you mentioned before to help a problem that as we found out isn't even caused by doctest! Many others would just reject people with such problems and I appreciate your help as such. Thanks again! I'm going to enjoy using doctest (especially the performance boost 😛) and will definitely recommend it to others. |
Fix the following building error on macOS. ``` Undefined symbols for architecture x86_64: "std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from: doctest::String doctest::detail::stringifyBinaryExpr<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char [13]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*, char const (&) [13]) in method.cc.1.o ld: symbol(s) not found for architecture x86_64 ``` See more at doctest/doctest#126. Fixes #649.
…em is this: when using clang from xcode - that means libc++. in that case I include <iosfwd> instead of forward-declaring std::ostream myself. Then if the user includes somewhere only the doctest header and <string> and then does a comparison - then and only then will there be some linker issue which I previously had managed to resolve by telling the users to also include <iostream> in that place in their tests. This is a toolchain issue when using the <iosfwd> header - the details are still not clear to me but I managed to get the linker to pull in what is necessary by adding a dummy unused global function in the implementation of doctest that uses operator<< of std::string to print to std::cout.
@arnavb finally resolved "properly" - turns out the problem is this: when using clang from xcode - that means libc++. in that case I include the |
…em is this: when using clang from xcode - that means libc++. in that case I include <iosfwd> instead of forward-declaring std::ostream myself. Then if the user includes somewhere only the doctest header and <string> and then does a comparison - then and only then will there be some linker issue which I previously had managed to resolve by telling the users to also include <iostream> in that place in their tests. This is a toolchain issue when using the <iosfwd> header - the details are still not clear to me but I managed to get the linker to pull in what is necessary by adding a dummy unused global function in the implementation of doctest that uses operator<< of std::string to print to std::cout.
FYI, I just ran into this issue with doctest 2.3.1 (macOS, apple-clang 10.0, libc++), with something as simple as this: #include <doctest/doctest.h>
#include <string>
TEST_CASE( "[console] console" )
{
REQUIRE( std::string("hello") == "hello" );
} (see the errors below). Adding explicit
|
@agurtovoy well that's unfortunate..... are you building with LTO? The only explanation I have is that this function gets optimized out: |
@onqtam Good guess, I was building a release build and had |
Gosh... I'll find a way to "fix" it - perhaps either with some magic attribute to that function or by calling it somewhere within doctest (after making it noinline so it doesn't get inlined and optimized out) |
I have the same issue with newer doctest versions (above 2.2.2). EXAMPLE: Fails to build test executable #include "doctest/doctest.h"
#include <string>
... WORK-AROUND 1: Succeeds to build test executable #include "doctest/doctest.h"
#include <string>
#include <sstream> // NEEDED-FOR: CMAKE_BUILD_TYPE=Release
... WORK-AROUND 2: Succeeds to build test executable #define DOCTEST_CONFIG_DISABLE 1
#include "doctest/doctest.h"
#include <string>
... Build details:
NOTE: |
@jenisys sorry for the late reply. Can you confirm that you are experiencing this with version 2.3.3 (the latest one) as well? That would be really unfortunate... I'm so puzzled as to why the linker would be reporting Using |
@onqtam |
Hi! I'm experiencing similar problems, in macOS and linux (archlinux, gcc 9.2), although not when using strings... |
@drehren I think in your case the problem could be solved by using |
Thanks @onqtam ! It did solve the issue. |
@drehren did you look in the FAQ? It's not mentioned there but I wonder if I should add an entry about this specific issue in there... |
@onqtam I did look through it now that I remember... I think an entry there would be great. |
I had the same issue, but only when I build with optimisations. I tried to update doctest to 2.4.4, but that did not help. So I added the include trick and that worked. The optimised build had asserts enabled, may try it without, but debug with asserts work fine. This was on macOS 10.13 Catalina. |
I had the same issue with doctest 2.4.6 building on macOS in release mode. |
This has finally been fixed by actually including the right headers with clang & libc++ - already in the |
…laring anything from std - hopefully fixing doctest#126 and doctest#356 at last
Description
I am trying to get my Travis CI build working with doctest (I'm switching from Catch to this for performance), but my build is not working on OSX (It is for Linux). In my Travis CI logs, I see the following error:
Steps to reproduce
I'm using CMake, and my invocation command is:
(
COMPILER
is set toclang++
andBUILD_TYPE
is set toDebug
andRelease
, both of which fail)The CMake configuration I am using is (for flags):
And the test configuration:
Extra information
The text was updated successfully, but these errors were encountered: