Perl C, XS help

PERL

    Next

  • 1. code on stonehenge.com for adding line numbers to code
    Dear all, I remember reading how Randal puts the =1= =2= in front of each line of code on his site, but I can't find it again. Anyone remember? Thanks. -- Just getting into the best language ever... Fancy a XXXX@XXXXX.COM ? Just ask!!!

Perl C, XS help

Postby paikkos » Tue, 02 Dec 2008 23:19:11 GMT

Hi,

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
help?

Thanx,
Dp.

Re: Perl C, XS help

Postby rob.dixon » Wed, 03 Dec 2008 02:04:09 GMT



You probably have a poor C compiler. Try changing the declaration to

  PerlInterpreter *my_perl;

As long as it is in main it should make no difference.

Rob

Re: Perl C, XS help

Postby paikkos » Wed, 03 Dec 2008 02:45:13 GMT

2008/12/1 Rob Dixon < XXXX@XXXXX.COM >:


....

Thanx Rob,

After a bit of googling, I found that the error usually refers to scoping issue.

With a bit of giggery-pokery I did

#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

I had to do that to a few files but I the principle was the same and
it worked :-)

I'd love to learn more C. I'm sure it would make me a better perler as
well as making my *NIX life easier.

Thanx again,
Dp.

Re: Perl C, XS help

Postby rob.dixon » Wed, 03 Dec 2008 02:58:43 GMT




Ah. Then you probably have a common header file (*.h) in all of the sources
where you should have added perl.h.

I encourage you to take the include out of all the sources you have modified and
try to spot that common header.

Rob

Similar Threads:

1.Help - Perl, XS and global constructors

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
in).

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.

Thanks.

2.Lighting effects filter doesn`t work properly in PS CS

Hi,

When i use the filter render > lighting effect... i can not use the default
settings. That`s no big deal for me, but it is a big deal for me that i can
not save or load my own lighting settings. Now i use PhotoShop 7 next with
PhotoShop CS just for that failure or bug in CS, because in PhotoShop 7, the
filter lighting effect works perfect!

Is there a patch for PhotoShop CS to get my Lighting Effects default
settings and that i can save/load my own lighting settings ?

Are more people have this problem ?

greetings,

Maurice


3.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
components
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 Makefile.pl
5. Perl Makefile.pl  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
'/SES/rajni/claudio/rajni/myModule/Code/factorial/Geometry/blib/arch/auto/Ge
ometry/Geometry.so' for module Geometry:
/SES/rajni/claudio/rajni/myModule/Code/factorial/Geometry/blib/arch/auto/Geo
metry/Geometry.so: undefined symbol: hypotenuse at
/usr/lib/perl5/5.8.8/i586-linux-thread-multi/DynaLoader.pm line 230.
 
Thanks
Rajni
 
 
 

DISCLAIMER
==========
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.

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

5.Help with xs: converting I32 to int ?

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

7. Calling multiple perl subroutines from XS procedure

8. debugging Perl/XS



Return to PERL

 

Who is online

Users browsing this forum: No registered users and 1 guest