Help - Perl, XS and global constructors



  • 1. /usr/lib/ Bad system id for shared library (jxc)
    # ./apachectl startssl /usr/lib/ Bad system id for shared library: /opt/seven6/usr/local/apache/libexec/mo /usr/lib/ Exec format error Syntax error on line 1103 of /opt/seven6/usr/local/apache/conf/httpd.conf: Cannot load /opt/seven6/usr/local/apache/libexec/ into server: Exec format er ror ./apachectl startssl: httpd could not be started who can tell me how to solve this ? I have 3 box, they are use same pkg and same version, same env ( path, classpath, shlib_path, etc). the other two, ux138160, ux138151 has no issues of that, just hpsgnry box, pls for hpsgnry box, to compare, I had download a standalone apache pkg and it also and let it pass. the issue alert of his bad system is generate by a 3rd parties build-in apache. I had search the google, some said they are patch, and path correction related errors. no exact answer there. ... XXXX@XXXXX.COM
  • 2. determine the screentype on your workstation
    Hi, does anybody know if there is a possibility in hp-ux to ask your system what type of screen you have connected ? HP workstation HP9000/785/B2600 Thanks, Frederik
  • 3. mount cdrom produces filemames with ";1" - HELP!
    Anybody on live? When we mount a cd-rom, all our file names have a semi-colon and 1 appended to them (e.g. STARTUP is STARTUP;1). We are trying an upgrade. What can we do about this (we have a call into HP, but sometimes we find quicker answers here). Thanks in advance! -- Raymond Lee

Help - Perl, XS and global constructors

Postby usenet.zaa.jabberwock » Sun, 08 May 2005 05:58:20 GMT

I have a third-party dynamic library that I'm trying to write an xsub
for.  It was written in C++, and it apparently has global constructors
that need to be initialized.  Building a static xsub works fine, but
the dynamic build always crashes in one function (naturally, it's a
function that needs to be called before almost all of the others in the
library).  With the static build running in wdb, I can actually see
code in the library being called from __do_global_ctors(), but not so
with a dynamic build, so I'm pretty sure it's a constructor problem.

Before I go into the gritty details, let me just ask the basic
question: can a dynamically loaded xsub be written for a library that
has global constructors that need to be initialized?

In my search for a solution, I came to believe that this was possible,
due to references to the CCsimple example in CookbookB.  It gives a
recipe for building a new perl executable that handles C++ constructors
(which I've done).  But how would perl know what constructors need to
be run, when the xsub (and hence the library) aren't loaded until the
perl interpreter starts running?  Did I misunderstand the CCsimple
example?  Note that my xsub code itself doesn't use c++, just the
library (and I only know that because it requires stdc++ to be linked

I'm running HPUX 11, with a perl 5.8.6 that I built myself.  I've tried
building perl and the xsub with the HP ANSI C compiler (we don't have
the c++ compiler), g++ (with ld for linking), and g++ (for both
compiling and linking, which of course eventually calls ld anyway).
They all seem to behave about the same.

Any suggestions/guidance?  I can give more details about the xsub once
someone confirms that this is indeed possible.


Re: Help - Perl, XS and global constructors

Postby Mike Stroyan » Sat, 14 May 2005 05:08:38 GMT

  Older versions of perl would load shared libraries on HP-UX by calling
shl_load with a BIND_NOSTART flag.  That prevented shared library
initializers from running and calling c++ constructors.  Your 5.8.6 version
of perl should have had that corrected already.  Apparently it is not
corrected.  Look for BIND_NOSTART in ext/DynaLoader/dl_hpux.xs of your
perl source and take it out.

Mike Stroyan,  XXXX@XXXXX.COM 

Re: Help - Perl, XS and global constructors

Postby usenet.zaa.jabberwock » Sat, 14 May 2005 21:58:44 GMT

No, I think dl_hpux.xs is correct.  Here's the applicable section:
    if (dl_nonlazy) {
    } else {
      bind_type = BIND_DEFERRED;
      /* For certain libraries, like DCE, deferred binding often causes
       * time problems.  Adding BIND_NONFATAL to BIND_IMMEDIATE still
       * unresolved references in situations like this.  */
      /* bind_type = BIND_IMMEDIATE|BIND_NONFATAL; */
    /* BIND_NOSTART removed from bind_type because it causes the shared
library's       */
    /* initialisers not to be run.  This causes problems with all of
the static objects */
    /* in the library.     */
    if (dl_debug)
        bind_type |= BIND_VERBOSE;
#endif /* DEBUGGING */
There's no other occurrence of BIND_NOSTART in the file.

It sounds like you're saying this should work though, which is
encouraging.  Maybe it's not as simple as the global constructors
simply not getting called (which is less encouraging).

Any tips on how to debug this with wdb?  I tried setting a breakpoint
in the library at the same place where it goes to in the static build,
and it never hit it.  But maybe there's something going wrong earlier.
I tried a "catch load", but I got lost pretty quickly trying to step
through the library loading with no debug info.

Thanks for your help!

Re: Help - Perl, XS and global constructors

Postby usenet.zaa.jabberwock » Sat, 14 May 2005 23:54:06 GMT

I was finally able to get dynamic loading to work, but it's not the
ideal solution (although it is usable).

I built a static perl with an empty xsub (as described in
CookbookB/CCsimple), but I also linked in *all* of the required
libraries (the vendor lists lots of shared libraries that need to be
linked to in addition to the one I'm writing the xsub for; previously,
I had only tried linking the new perl with the one where it was
crashing).  Using this perl, I can now dynamically load the extension
for the library I want to access.

I'm guessing that this makes the program's startup code aware of the
libraries, and it handles the initialization just as if it were a full
static build.  Since the libraries in question are still shared, the
new perl executable isn't any bigger than the original (in fact, it's a
little smaller for some odd reason).  I suppose I could also rebuild
perl from scratch and give these as required libraries, but this is

The really bad thing was that I had to do the link by hand.  I tried
defining LIBS in the "perl Makefile.PL" command line, but it didn't get
passed to the final link.  No idea why.

I'd still like a better solution if someone can come up with one, but I
can live with this.

Similar Threads:

1.C++ global constructors in xsub?

Rather than bog this post down with my particular details, I'll just
ask the basic question:

Is it possible to write a dynamically-loaded xsub for a library that
has C++ global constructors?

I've googled this question to death and I haven't found a definite
answer one way or the other, although one post led me to believe that
building a new perl binary as described in CookbookB/CCsimple would
solve the problem.  It didn't, and I'm not sure how it could, but maybe
I'm missing something.

If I get a "yes", I'll follow up with the gory details of my problem.
But just so it's not completely open-ended, I'm running under HPUX
11.11, perl 5.8.6 (but I'd be willing to rebuild perl any way anyone

2.Calling SUPER::constructor in the constructor

Is it possible to call the constructor that a function inherits from its
parent?  I tried calling SUPER:: and SUPER-> in a constructor and got
errors.  Am i correct in assuming that if I rewrite the constructor that
a copy of the parent object won't be available?

Thanks in advance,


3.Perl C, XS help


I am trying port an Custom Perl module from one server to another. The
module uses C/XS and was built in 2001/2. I got the source and did
`perl Makefile.PL; make`. There was an error in one .c file:

store.c:592: error: 'my_perl' undeclared (first use in this function)
store.c:592: error: (Each undeclared identifier is reported only once
store.c:592: error: for each function it appears in.)

I solved that by adding

'static PerlInterpreter *my_perl;'  near the top of the file.

After make distclean; perl Makefile, make and the same error with a
different file. This time however, once I added the static declaration
I got this error:

store.c:13: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '*' token

It refers to the static declaration mentioned above.

I am a super newbie when it comes to C and I know this might be
straying OT but does anyone know how I can make this static declartion
in the correct way or perhaps point me to a list that might be able to


4.XS help

Hello All,
I'm trying to call C routine from Perl using XS but some how my 'make test'
is failing. Following are the steps I did :
file: hypotenuse.h
      double hypotenuse(double x, double y); /* Func Declaration */
file: hypotenuse.c
      /* Func Definition */
     double hypotenuse(double x, double y)
           return sqrt(x*x + y*y);

Steps :
1.  h2xs -n Geometry -A -O -x -F '-I ../..' hypotenuse.h   /created XS
2. cd Geometry               // Went in the directory
3. cp ../hypotenuse.* .     // Copied header and source files in Dir
4. Added Geometry.o and hypotenuse.o as objects in
5. Perl  and make is ok
6. 'make test' is failing 
Do someone have any idea where I'm going wrong? I did not read perl doc for
XS yet :(.
Error logs:
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e"
"test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/Geometry....NOK 1
#   Failed test 'use Geometry;'
#   in t/Geometry.t at line 9.
#     Tried to use 'Geometry'.
#     Error:  Can't load
ometry/' for module Geometry:
metry/ undefined symbol: hypotenuse at
/usr/lib/perl5/5.8.8/i586-linux-thread-multi/ line 230.

This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

5.Help w/Class::Date Date.xs

6. Help with xs: converting I32 to int ?

7. Problem using more than 1 module in Windows (XS) - please help

8. Copy constructor and Dup method in Perl

Return to hp


Who is online

Users browsing this forum: No registered users and 21 guest