Tests built with Clang, c++11, and libc++ fail to link?

2,077 views
Skip to first unread message

Chris Caloggero

unread,
Sep 5, 2013, 4:20:30 PM9/5/13
to googletes...@googlegroups.com
Hello,

New to using the framework, and I'm sure I'm just doing something dumb, but I can't seem to find a solution, despite tirelessly searching. I do want to note, though, that I was able to find some basic information on the topic relating to c++98 on these boards (https://groups.google.com/forum/#!topic/googletestframework/F1B9LArL9_U), but it isn't too helpful to me in my current scenario. It seems as those the former solution was to patch the gtest-port.h file to get past some minor compatibility issues, which appear to have since been incorporated into the main development branch of the framework (at least as of version 1.7.0 RC1). Anywho, here is my problem...

As I said, new to the GTest framework, but have managed to compile it with Cmake, and got it installed and operational (for the most part). My problem lies in the process of converting a few smaller programs to c++11, and trying to associate unit tests with them during the conversion process. My typical (functioning) compilation statement for the tests looks like the following:

clang++ -std=c++11 -lgtest <file.cpp> -o <file>

Nothing too outrageous, but for several of the programs I need to link against the libc++ variant of the standard library in order to incorporate some desired functionality (it appears to be a bit more feature complete). Upon using the -stdlib=libc++ option, it all fails... Any suggestions on how to alleviate this issue? Is this simple because the framework doesn't fully support c++11 yet?

I've tried doing this on the latest version of OS X (10.8.4) and on Ubuntu 12.04, merely using sample1 in the official documentation to test against. OS X will compile and run smoothly on tests that don't require libc++, but those that do will give me an extremely verbose linking error. As for Ubuntu, I can't get it to budge either way; there are different (from OS X), but still largely verbose, linking errors I can't seem to get past (with or without the inclusion of libc++)...

Thanks in advance for the help, and, again, I apologize if there are any redundancies in my question compared to any other open threads!

- Chris

Josh Kelley

unread,
Sep 5, 2013, 10:16:12 PM9/5/13
to Chris Caloggero, Google C++ Testing Framework
Did you compile and link Google Test with -std=c++11 and libc++?  If Google Test and your application are using different C++ Standard Library implementations or possibly different (C++98 versus C++11) ABIs, I'd expect some problems.

There's a few discussions about this online; for example:
http://stackoverflow.com/q/8454329/25507
http://gcc.gnu.org/wiki/Cxx11AbiCompatibility

--
Josh Kelley


--
 
---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Chris Caloggero

unread,
Sep 5, 2013, 11:57:41 PM9/5/13
to googletes...@googlegroups.com, Chris Caloggero
Woohoo! That seems to have worked, upon looking over the links you referenced, I found this SO answer, solving the exact issue described:


Hopefully, that link can help anyone else who ends up in the same situation as myself, as it seems to have fixed the problem!

Thanks, Josh!
- Chris

Zhanyong Wan (λx.x x)

unread,
Sep 6, 2013, 4:11:13 PM9/6/13
to Chris Caloggero, Google C++ Testing Framework
Also see:

https://groups.google.com/forum/#!searchin/googletestframework/considered$20harmful/googletestframework/Zo7_HOv1MJ0/F4ZBGjh_ePcJ

In general, you should not install a compiled gtest library on your machine, as it's likely you'll build tests with different compiler flags (including -D) on that machine, and a mismatch between the flags used for building gtest and the flags used for building your tests will lead to many subtle problems.  Instead, build gtest as part of a project and use it within that project, s.t. different projects can use different compiler flags without stepping on each other.


--
 
---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Zhanyong
Reply all
Reply to author
Forward
0 new messages