In the README file for gtest and gmock, we said that you could install
compiled gtest and gmock libraries on *nix systems using 'make
install'. Then every user of your machine can write tests without
recompiling gtest or gmock.
This seemed like a good idea when we wrote the README, but it has a
got-cha: every user needs to compile his tests using the same compiler
flags used to compile the installed gtest/gmock libraries; otherwise
he may run into undefined behaviors (i.e. the tests can behave
strangely and may even crash for no obvious reasons).
Why? Because C++ has this thing called the One-Definition Rule: if
two C++ source files contain different definitions of the same
class/function/variable, and you link them together, you violate the
rule. The linker may or may not catch the error (in many cases it's
not required by the C++ standard to catch the violation). If it
doesn't, you get strange run-time behaviors that are unexpected and
hard to debug.
If you compile gtest and your test code using different compiler
flags, they may see different definitions of the same
class/function/variable (e.g. due to the use of #if in the code).
Therefore, for your sanity, we recommend to avoid using the installed
gtest/gmock libraries. Instead, each project should compile
gtest/gmock itself such that it can be sure that the same flags are
used for both gtest/gmock and the tests.
For this reason, we now consider it a bad practice to run 'make
install'. We'll remove the instructions from README soon. Thanks,
--
Zhanyong
Hi Dmytro,
2010/3/25 Dmytro Ovdiienko <dmitriy....@gmail.com>:
> Hi Zhanyong,
>
> According to this logic we should not use installed boost, xerces,
> openssl etc. It is not useful.
Boost is mostly a header-only library, so the logic doesn't apply there.
Not sure about xerces and openssl.
> IMHO it is better to create some guards/fences and not allow user to
> link application or create option-neutral interface.
--
Zhanyong
(adding the mailing lists back)
Hi Dmytro,
2010/3/25 Dmytro Ovdiienko <dmitriy....@gmail.com>:
> Hi Zhanyong,
>
> According to this logic we should not use installed boost, xerces,
> openssl etc. It is not useful.
Boost is mostly a header-only library, so the logic doesn't apply there.
Not sure about xerces and openssl.
gtest has many classes/functions whose definitions are controlled by
#if. If you pass different -DGTEST_HAS_FOO=1 flags to different
translation units, you'll violate the ODR. Or sometimes people use -D
to select which malloc library to use (debug vs release), and you have
to use the same malloc library across the board.
--
Zhanyong
Hi KjellKod,
2011/7/1 KjellKod <kjell.h...@gmail.com>:
>
> One problem with 1.6 is that previously it was easy to have example
> source code
> with a simple prerequisite that to compile the example you needed
> gtest installed.
>
> With 1.6 this is no longer possible. One way to do it is as you
> suggest, to have
> the example appended with gtest-1.6 and when making the example also
> building and linking gtest.
>
> Well, a small example just grew tremendously and all of a sudden gtest
> is not so easy to use anymore. I understand the reasons you state
> above but I don't think the solution is as good as it should be :(
>
> Regards
> KjellKod
>
> FYI:
>
>
> Simple steps like the ones below is only in my memory now:
> Some www user downloads an example, realizes that he needs gtest as
> well and downloads and unzips it.
>
> cd gtest--some-version
> ./configure
> make
> make install
>
> cd ~/some_example;
> ./make
> ./run_some_example_executable
The new workflow would be:
download a gtest release package and unpack it (no need to configure or make)
download the example
edit Makefile in the example to point to the directory where gtest is unpacked
make
run the example executable
See http://code.google.com/p/googletest/source/browse/trunk/make/Makefile
for an example on what the Makefile in the example should look like.
Thanks,
>
>
>
>
>
>
>
>
>
> On Jan 17 2010, 9:15 am, Zhanyong Wan (λx.x x) <w...@google.com>
--
Zhanyong
2010/3/25 Dmytro Ovdiienko wrote:
> Hi Zhanyong,
>
> According to this logic we should not use installed boost, xerces,
> openssl etc. It is not useful.