googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Add extern "C" to main entry point

Open xiaoxiang781216 opened this issue 3 years ago • 3 comments

since the bare metal or RTOS environment need demangled name

xiaoxiang781216 avatar Sep 12 '22 17:09 xiaoxiang781216

It is my understanding that main() is special and never mangled. Can you elaborate on what is going on here?

Since all source codes are built into one image in bare metal or RTOS environment, we can't have main entry point more than once. To fix this limitation, one approach is:

  1. Add -Dmain=xxx_main when compile source files which contain main entry point
  2. Create a table contain all possible entry point like this:
{"gtest", gtest_main, ...},
{"gmock", gmock_main, ...},

A special shell will lookup this table to find and launch the entry point. extern "C" mark can fix the issue in this case.

xiaoxiang781216 avatar Sep 14 '22 04:09 xiaoxiang781216

You should simply not link with great main and add your own main function see the examples

nicola-lunghi avatar Feb 28 '23 08:02 nicola-lunghi

Yes, this is one of approach.

xiaoxiang781216 avatar Feb 28 '23 13:02 xiaoxiang781216