gpt4 book ai didi

c++ - 为什么建议包含googletest源文件

转载 作者:行者123 更新时间:2023-12-01 14:50:19 24 4
gpt4 key购买 nike

只是一个简单的问题,
为什么建议通过包含源文件来在每个项目中编译googletest和googlemock(而不是使用cmake扩展名为'.a'的库,然后将其链接到许多项目)。

来源:https://www.jetbrains.com/help/clion/creating-google-test-run-debug-configuration-for-test.html

最佳答案

因为googletest产生的“.a”文件会根据编译器标志而有所不同。您要进行的不同测试项目可能会设置不同的项目,如果它们引用通用的googletest'.a'文件,则可能会导致问题。

'make install' considered harmful:

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).

关于c++ - 为什么建议包含googletest源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55237629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com