如何使用隐藏的可见性构建Google测试
当我为库构建单元测试(该图书馆构建的单位测试)时,我遇到了大约400个格式的警告:
direct access in function 'testing::internal::SuiteApiResolver<MyTestSuite>::GetTearDownCaseOrSuite(char const*, int)' from file 'libgtestd.a(gtest-all.o)' to global weak symbol 'testing::Test::TearDownTestSuite()' from file 'test_filemame.o' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
通过更改Googletest的选项 gtest_hide_internal_symbols
从 off off off off off 代码>在上,警告数量大大减少。但是,我仍然对这种类型有一些警告:
direct access in function 'testing::internal::SuiteApiResolver<testing::internal::(anonymous namespace)::FailureTest>::GetTearDownCaseOrSuite(char const*, int)' from file 'libgtestd.a(gtest-all.o)' to global weak symbol 'testing::Test::TearDownTestCase()' from file 'test_mytest.o' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
有人可以解释为什么警告仍然存在时,当我已经打开 gtest_hide_internal_symbols
选项时?我想念什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定GTEST,但我已经看到了LD的这些警告。
您可能会收到有关子模块或依赖项的所有这些警告,其中
gtest_hide_internal_symbols
是 not 打开。我的猜测是
gtest_hide_internal_symbols
控制gcc/llvm选项-fvisiblility
。具体来说,gtest_hide_internal_symbols
on 可能设置-fvisibility = hidden
。更新:
我的假设是正确的。
请参阅。
cmake_cxx_visibility_preset
指定-fvisibilibily
andcmake_visibility_inlines_hidden
指定-Fvisibility-Inlines-Inlines-inlines-hidden-Hidden-Hidden-hidded
。I'm not sure about GTest, but I have seen these warnings from LD.
You probably receive all of these warnings for sub-modules or dependencies, wherein
gtest_hide_internal_symbols
is not turned on.My guess is that
gtest_hide_internal_symbols
controls the GCC/LLVM option-fvisiblility
. Specifically, turninggtest_hide_internal_symbols
toON
probably sets-fvisibility=hidden
.UPDATE:
My assumption was correct.
See https://github.com/google/googletest/blob/830fb567285c63ab5b5873e2e8b02f2249864916/googletest/CMakeLists.txt#L80.
CMAKE_CXX_VISIBILITY_PRESET
specifies-fvisibility
andCMAKE_VISIBILITY_INLINES_HIDDEN
specifies-fvisibility-inlines-hidden
.