no_name
no_name

Reputation: 45

How to build google test with hidden visibility

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?

Upvotes: 0

Views: 695

Answers (1)

Oliver
Oliver

Reputation: 1655

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.

Upvotes: 1

Related Questions