7

In our application we use several dynamically linked libraries. We recently updated the version of one of these libraries. The developers of that library are providing a main method since this new version (Doing nothing more than printing Hello World).

The problem is that we are using GTest and GMock, which generate their own main method. When we now run our test binary, we just get "Hello World", so the wrong main method is being taken.

How can we force the main method of the tests to be used?

UPDATE: This seems to be a GMock/GTest issue. The main method is normally generated, but this is not the case as it finds an already existing main method now.

vegemite4me
  • 6,621
  • 5
  • 53
  • 79
W. Goeman
  • 1,674
  • 2
  • 15
  • 31

2 Answers2

5

There are no ways around in your situation. You'll have to remove the main from the shared library. It simply doesn't belong there.

BЈовић
  • 62,405
  • 41
  • 173
  • 273
  • I fully agree with your statement. It will be horrible to get the developers from that lib to change it. I was hoping for a quick and dirty trick to "ignore" that main method. – W. Goeman Mar 14 '12 at 09:35
  • @W.Goeman If it is an open source library, then you can do it yourself, no? If it is a commercial library, then they should do it. In any case, it is a serious problem for a shared library to define the main(). – BЈовић Mar 14 '12 at 09:57
  • 1
    we contacted the developers from that library and they promised a fix. A main method in a library seems to be a serious issue indeed :) – W. Goeman Mar 14 '12 at 10:30
  • I don't think /lib/x86_64-linux-gnu/libc.so.6 having a main is a problem also running the lib you can "human check" the version (e.g. ./libfoo.so printing build version). I guess it's more a library linking order issue – Mizux May 02 '18 at 09:46
1

I had a similar issue with two libraries having main methods, which was resolved by changing the order of the libraries to the linker.

pytflyt
  • 11
  • 1