I wouldn't build an .so that has a main defined.

That's like saying that you wouldn't write two classes that exported the same named method.

There is nothing magical about the name:main, and there is absolutely no conflict between having a main in a dynamically linked library and the "main" (if it has one), in the executable that dynamically links to that library.

Indeed, it is easy to demonstrate that any executable (with or without a main of its own), can perfectly safely dynamically link to 2, 3 or 200 .so/.dlls that each export their own routine called "main" (or anything else). Once you have (runtime) loaded the library, you query the address of the "main" routine by name and assign the results to a variable (function pointer). You can easily have an array of function pointers, each initialised with the address of a routine named "main" in each of as many .sos as you care to load, and call them all with no confict whatsoever.

You wouldn't be able to statically link them to the executable, but why would you try?

but the examples do segfault on every *nix box I run...

That I really do not understand, and would appreciate your help in understanding it. (Can anyone else conform this under linux?)

What happens if you rename the "main" routine in the final example to say: "mainx"?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^7: Plz suggest what is the problem in the following code? by BrowserUk
in thread Plz suggest what is the problem in the following code? by sanjay nayak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.