[haiku-development] Re: main() in shared libraries?

  • From: Adrien Destugues <pulkomandy@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 23 Apr 2015 18:58:57 +0200

On Thu, Apr 23, 2015 at 04:09:53PM +0200, François Revol wrote:

On 23/04/2015 15:00, François Revol wrote:
I've looked into porting Gambas3 <http://gambas.sourceforge.net/> and I
noticed this in the configure tests:

AC_CHECK_LIB(gcc_s, main, CXX_LIB="$CXX_LIB -lgcc_s")
AC_CHECK_LIB(stdc++, main, CXX_LIB="$CXX_LIB -lstdc++")

Obviously it fails on Haiku because they don't have a main() call.

Do we want to mimic the linux behaviour or fix those checks (but then
I'm not sure which symbol to test for on those)?

I found some unmangled symbols to test for for those. For the record:

AC_CHECK_LIB(gcc_s, _Unwind_Resume, CXX_LIB="$CXX_LIB -lgcc_s")
AC_CHECK_LIB(stdc++, __cxa_throw, CXX_LIB="$CXX_LIB -lstdc++")

Still, it's probably not the only case with those ugly tests.

This does not need a main function inthe library to work. AC_CHECK_LIB
generates something like this:

int main ()
{
main ();
return 0;
}

and checks that it compiles and links. In C, it should, since there IS a
main function in that file. However, in C++ it is not allowed to call
main and gcc will emit an error when set to strict standards:
http://lists.gnu.org/archive/html/autoconf/2006-09/msg00019.html

I don't know of a better solution, but at least the check for "main"
works for all C libraries.

--
Adrien.

Other related posts: