如何使用隐藏的可见性构建Google测试

发布于 2025-01-24 16:44:42 字数 1242 浏览 3 评论 0 原文

当我为库构建单元测试(该图书馆构建的单位测试)时,我遇到了大约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 选项时?我想念什么?

When I build unit tests for a library (which is built with hidden visibility), I encounter about 400 warnings of this format:

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.

By changing the googletest's option gtest_hide_internal_symbols from OFF to ON, the number of warnings greatly decrease. However, I still have some warnings of this type:

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.

Can someone explain why the warnings still exist, when I already turn on gtest_hide_internal_symbols option? What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终陌 2025-01-31 16:44:42

我不确定GTEST,但我已经看到了LD的这些警告。

您可能会收到有关子模块或依赖项的所有这些警告,其中 gtest_hide_internal_symbols not 打开。

我的猜测是 gtest_hide_internal_symbols 控制gcc/llvm选项 -fvisiblility 。具体来说, gtest_hide_internal_symbols on 可能设置 -fvisibility = hidden

更新:

我的假设是正确的。

请参阅

 如果(gtest_hide_internal_symbols)
  set(cmake_cxx_visibility_preset隐藏)
  set(cmake_visibility_inlines_hidden 1)
endif()
 

cmake_cxx_visibility_preset 指定 -fvisibilibily and cmake_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, turning gtest_hide_internal_symbols to ON probably sets -fvisibility=hidden.

UPDATE:

My assumption was correct.

See https://github.com/google/googletest/blob/830fb567285c63ab5b5873e2e8b02f2249864916/googletest/CMakeLists.txt#L80.

if (gtest_hide_internal_symbols)
  set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif()

CMAKE_CXX_VISIBILITY_PRESET specifies -fvisibility and CMAKE_VISIBILITY_INLINES_HIDDEN specifies -fvisibility-inlines-hidden.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文