google / googletest

GoogleTest - Google Testing and Mocking Framework

Home Page:https://google.github.io/googletest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: gtest_main.so doesn't contain symbols from gtest.so

yurivict opened this issue · comments

Describe the issue

gtest_main.so built by the FreeBSD port doesn't contain symbols normally found in gtest.so

Is gtest_main.so documented anywhere? Is it supposed to only have the main symbol, or also all symbols from gtest.so?

This post says:

[...] inconsistent part is that gtest_main sometimes also includes everything from gtest, so that you only need to link against either gtest (if you want to write your own main() method) or gtest_main [...]

It isn't clear what does it mean "gtest_main sometimes also includes everything from gtest".

Many projects only link with gtest_main and it works somehow.

So is gtest_main supposed to be a complete replacement of gtest + the main function, or not?

Could you please document gtest_main and clearly define there what does it contain?

Steps to reproduce the problem

n/a

What version of GoogleTest are you using?

googletest-1.14.0

What operating system and version are you using?

FreeBSD 14.0

What compiler and version are you using?

clang-16

What build system are you using?

cmake

Additional context

No response

It sounds like you are confusing gtest_main, which is a build target, and gtest_main.so, which is a shared object file. If you are using a supported build system (Bazel, CMake), the build target should transitively link everything, including gtest, necessary when linking gtest_main. The so file itself will not contain anything but main. However, you should not rely on transivitivty. If you directly use a symbol, you should specify the corresponding dependency. And don't refer to .so files at all. Let a build system figure that part out for you.

Several projects just link with -lgtest_main and it works somehow in some cases, and doesn't work in other cases.