linking against already compiled gtest library

367 views
Skip to first unread message

Ernast Sevo

unread,
Feb 1, 2016, 4:11:14 PM2/1/16
to Google C++ Testing Framework
Hello,

  I have recently been using gtest and wanted to start deploying it so it could be used by multiple people. I did want
others to deal with building gtest on their own and was hoping to provide others with the library so they could link against it.

However, recently I came across this:
 (https://github.com/google/googletest/blob/master/googletest/docs/FAQ.md#why-is-it-not-recommended-to-install-a-pre-compiled-copy-of-google-test-for-example-into-usrlocal)

My compiler/linker knowledge is very minimal and I have done some research but still don't have quite a good understanding of this
issue. Here are my questions:

1. Why isn't the problem described in the link above an issue for other libraries?
2. Why would compiling both gtest and the application under test with the same flags fix this issue?

Thank you,

 Ernast

Craig Scott

unread,
Feb 1, 2016, 4:28:27 PM2/1/16
to Ernast Sevo, Google C++ Testing Framework
It can indeed be an issue for other libraries too, not just GoogleTest, it's just that GoogleTest is being a bit more explicit about it by mentioning it in its documentation. For the most part, it's a bigger problem on Windows than other platforms due to different runtime libraries being linked for Debug and Release builds. When you build gtest and your application in the same build, they will (generally) use the same compiler/linker settings. This means you don't end up with incompatibilities between runtimes or other behavioural issues that can arise when you use different compiler flags which cause code to be built differently.

Building gtest as part of your build doesn't have to be super difficult. This article shows one way to do it robustly. I submitted a pull request here to update the GoogleTest Readme.md with this technique.



--

---
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/d/optout.



--
Craig Scott
Melbourne, Australia
Reply all
Reply to author
Forward
0 new messages