in reply to Re: Plz suggest what is the problem in the following code?
in thread Plz suggest what is the problem in the following code?

Hmmm ... this is either an OS issue or a compiler issue. On my up-to-date ubuntu boxes, your examples segfault. I chalked it up to the two mains issue (which if not a cross-platform bug is at least bad form). I can see where dynamic loading after the interpreter could let you load a shared object that has another main defined (and from what I can tell, Inline does no type of name mangling) so ... maybe that behavior is undefined?

-derby
  • Comment on Re^2: Plz suggest what is the problem in the following code?

Replies are listed 'Best First'.
Re^3: Plz suggest what is the problem in the following code?
by BrowserUk (Patriarch) on Feb 03, 2009 at 23:00 UTC

    What does the .xs file look like for the final example? Mine looks like this:

    #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "INLINE.h" int main( int argc, AV *argv ) { int i; for( i=0; i< argc; i++ ) { printf( "%s\n", SvPVX( av_fetch( argv, i, NULL ) ) ); } return 0; } MODULE = junk7_pl_b750 PACKAGE = main PROTOTYPES: DISABLE int main (argc, argv) int argc AV * argv

    I can't see anything there that is platform, or compiler dependant?


    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.

      Exactly the same (below). Now at compile time, I cannot link two objects that have main defined - I get a "multiple definition of 'main'" error .. but when I try to dynamically load a shared object that has another main defined, no problem. Hmmm ... may be a problem with my install of perl or Inline ....

      #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "INLINE.h" int main( int argc, AV *argv ) { int i; for( i=0; i< argc; i++ ) { printf( "%s\n", SvPVX( *av_fetch( argv, i, NULL ) ) ); } return 0; } MODULE = test_pl_bcca PACKAGE = main PROTOTYPES: DISABLE int main (argc, argv) int argc AV * argv
      -derby
        I cannot link two objects that have main defined - I get a "multiple definition of 'main'" error

        When you link Inline::C code, you are building an .so file, and the only things exported by that .so should be the external routines defined within it.

        Why would it have two mains defined? Or if it only has one, what else (other object) are you trying to link with it that has also has a main defined?

        I know how litte I know about *nix build processes (next to nothing), but I really cannot see where the other main is coming from in your scenario?

        It can't be the main in the perl executable, because you are not trying to link the .so and the (currently running) perl executable together. That would be static linking.


        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.