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

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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^4: Plz suggest what is the problem in the following code?
by derby (Abbot) on Feb 04, 2009 at 11:57 UTC

    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.

        I wouldn't normally define two mains ... that was just a contrived test. By convention (cargo-cult, angry monkey, never had a need to, ...), I wouldn't build an .so that has a main defined. I mistook my segfaulting with the examples as a two 'mains' issue but apparently that's just a red herring. The examples do segfault on every *nix box I run it on - Ubuntu/5.10, Ubuntu/5.8, RedHat/5.8 - and just changing the function name from main to xmain make them run fine.

        -derby