Operating System - HP-UX
1752794 Members
5661 Online
108789 Solutions
New Discussion юеВ

perl points to incorrect @INC when embedded in a "C" code

 
Syed Madar J S
Frequent Advisor

perl points to incorrect @INC when embedded in a "C" code

Hi,

I am trying to embed perl script in C code, but hit upon an incorrect @INC reference in the process.

Hence, i tried to reduce the test case as follows.

----

"perl -V" gives the following @INC Path:

@INC:
/opt/perl_32/lib/5.8.8/PA-RISC1.1-thread-multi
/opt/perl_32/lib/5.8.8
/opt/perl_32/lib/site_perl/5.8.8/PA-RISC1.1-thread-multi
/opt/perl_32/lib/site_perl/5.8.8
/opt/perl_32/lib/site_perl
/opt/perl_32/lib/vendor_perl/5.8.8/PA-RISC1.1-thread-multi
/opt/perl_32/lib/vendor_perl/5.8.8
/opt/perl_32/lib/vendor_perl
-------

# cat main.c
#include /* from the Perl distribution */
#include /* from the Perl distribution */

static PerlInterpreter *my_perl; /*** The Perl interpreter ***/

int main(int argc, char **argv, char **env)
{
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
perl_run(my_perl);
perl_destruct(my_perl);
perl_free(my_perl);
}

#cc -o interpreter main.c `perl -MExtUtils::Embed -e ccopts -e ldopts`

#cat show.pl
#!/usr/bin/perl
sub BEGIN
{
map {print STDERR "INC: $_\n"} @INC;
#push (@INC, "/opt/perl_32/lib/5.8.8/PA-RISC1.1-thread-multi");
#push (@INC, "/opt/perl_32/lib/site_perl/5.8.8/PA-RISC1.1-thread-multi");
#push (@INC, "/opt/perl_32/lib/vendor_perl/5.8.8/PA-RISC1.1-thread-multi");

#map {print STDERR "INC: $_\n"} @INC;
}

## ./interpreter show.pl
INC: /opt/perl_32/lib/5.8.8/PA-RISC2.0-thread-multi
INC: /opt/perl_32/lib/5.8.8
INC: /opt/perl_32/lib/site_perl/5.8.8/PA-RISC2.0-thread-multi
INC: /opt/perl_32/lib/site_perl/5.8.8
INC: /opt/perl_32/lib/site_perl
INC: /opt/perl_32/lib/vendor_perl/5.8.8/PA-RISC2.0-thread-multi
INC: /opt/perl_32/lib/vendor_perl/5.8.8
INC: /opt/perl_32/lib/vendor_perl
INC: .


# ls /opt/perl_32/lib/5.8.8/PA-RISC2.0-thread-multi
/opt/perl_32/lib/5.8.8/PA-RISC2.0-thread-multi not found


Please provide inputs, i have no clue how this incorrect/non-existent @INC is getting printed !
6 REPLIES 6
Syed Madar J S
Frequent Advisor

Re: perl points to incorrect @INC when embedded in a "C" code

Adding further:

the "-v" option gives a different value for the original perl interpreter and the interpreter-instance created by me

# perl -v

This is perl, v5.8.8 built for PA-RISC1.1-thread-multi

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

# ./interpreter -v

This is perl, v5.8.8 built for PA-RISC2.0-thread-multi

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
James R. Ferguson
Acclaimed Contributor

Re: perl points to incorrect @INC when embedded in a "C" code

Hi:

I suspect if you do:

# cc -o interp interp.c `/opt/perl_64/bin/perl -MExtUtils::Embed -e ccopts -e ldopts`

# ./interp -le 'print map "$_\n",@INC'

...and:

# cc -o interp interp.c `/opt/perl_32/bin/perl -MExtUtils::Embed -e ccopts -e ldopts`

# ./interp -le 'print map "$_\n",@INC'

...that your results are as expected.

What do your symbolic links look like for the folling (mine shown):

# ls -l /opt/perl
lrwxr-xr-x 1 root sys 12 Sep 11 2007 /opt/perl -> /opt/perl_64
smhfpg # ls -ld /opt/perl_64
dr-xr-xr-x 6 bin bin 8192 Oct 10 2008 /opt/perl_64
smhfpg # ls -ld /opt/perl_64/bin/perl
lrwxr-xr-x 1 bin bin 13 Aug 17 2006 /opt/perl_64/bin/perl -> ./perl-static
smhfpg # ls -ld /opt/perl_32/bin/perl
lrwxr-xr-x 1 bin bin 13 Aug 17 2006 /opt/perl_32/bin/perl -> ./perl-static

Regards!

...JRF...
Syed Madar J S
Frequent Advisor

Re: perl points to incorrect @INC when embedded in a "C" code

Hi James,

Thanks for the pointer, but it didn't help though.

Log:
=====
hpmdd78# cc -o interpv1 main.c `/opt/perl_64/bin/perl -MExtUtils::Embed -e ccopts -e ldopts`
hpmdd78# ./interpv1 -le 'print map "$_\n",@INC'
/opt/perl_64/lib/5.8.8/PA-RISC2.0-thread-multi-LP64
/opt/perl_64/lib/5.8.8
/opt/perl_64/lib/site_perl/5.8.8/PA-RISC2.0-thread-multi-LP64
/opt/perl_64/lib/site_perl/5.8.8
/opt/perl_64/lib/site_perl
/opt/perl_64/lib/vendor_perl/5.8.8/PA-RISC2.0-thread-multi-LP64
/opt/perl_64/lib/vendor_perl/5.8.8
/opt/perl_64/lib/vendor_perl
.

hpmdd78# cc -o interpv2 main.c `/opt/perl_32/bin/perl -MExtUtils::Embed -e ccopts -e ldopts`
hpmdd78# ./interpv2 -le 'print map "$_\n",@INC'
/opt/perl_32/lib/5.8.8/PA-RISC2.0-thread-multi
/opt/perl_32/lib/5.8.8
/opt/perl_32/lib/site_perl/5.8.8/PA-RISC2.0-thread-multi
/opt/perl_32/lib/site_perl/5.8.8
/opt/perl_32/lib/site_perl
/opt/perl_32/lib/vendor_perl/5.8.8/PA-RISC2.0-thread-multi
/opt/perl_32/lib/vendor_perl/5.8.8
/opt/perl_32/lib/vendor_perl
.


The change seen was that "PA-RISC2.0-thread-multi" and "PA-RISC2.0-thread-multi-LP64".

But the ideal case must ne "PA-RISC1.1-thread-multi" instead of "PA-RISC2.0-thread-multi" in the "perl_32" build :(

The symbolic links are different from yours mine is pointing to /opt/perl_32, the rest are similar.


hpmdd78# ls -l /opt/perl
lrwxr-xr-x 1 root sys 12 Jun 10 10:22 /opt/perl -> /opt/perl_32
hpmdd78# ls -ld /opt/perl_64
dr-xr-xr-x 6 bin bin 96 May 27 11:57 /opt/perl_64
hpmdd78# ls -ld /opt/perl_64/bin/perl
lrwxr-xr-x 1 bin bin 13 Jun 10 10:23 /opt/perl_64/bin/perl -> ./perl-static
hpmdd78# ls -ld /opt/perl_32/bin/perl
lrwxrwxrwx 1 root sys 13 Jun 10 15:21 /opt/perl_32/bin/perl -> ./perl-static
James R. Ferguson
Acclaimed Contributor

Re: perl points to incorrect @INC when embedded in a "C" code

Hi (again):

Does running the following show anything unexpected?

# /opt/perl_32/bin/perl -MExtUtils::Embed -le ccopts

# /opt/perl_32/bin/perl -MExtUtils::Embed -le ldopts

...or for that matter, compared to:

# perl -MExtUtils::Embed -le ccopts

# perl -MExtUtils::Embed -le ldopts

Posting your output might be insightful.

Regards!

...JRF...
Syed Madar J S
Frequent Advisor

Re: perl points to incorrect @INC when embedded in a "C" code

Nope, there is no difference:

hpmdd78# /opt/perl_32/bin/perl -MExtUtils::Embed -le ccopts
-D_POSIX_C_SOURCE=199506L -D_REENTRANT -Ae -D_HPUX_SOURCE -Wl,+vnocompatwarnings +DAportable +DS2.0 +Z -DUSE_SITECUSTOMIZE -DNO_HASH_SEED -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/opt/perl_32/lib/5.8.8/PA-RISC1.1-thread-multi/CORE
hpmdd78# /opt/perl_32/bin/perl -MExtUtils::Embed -le ldopts
-Wl,-E -Wl,-B,deferred /opt/perl_32/lib/5.8.8/PA-RISC1.1-thread-multi/auto/DynaLoader/DynaLoader.a -L/opt/perl_32/lib/5.8.8/PA-RISC1.1-thread-multi/CORE -lperl -lcl -lcres -lnsl -lnm -lmalloc -ldld -lm -lcrypt -lsec -lpthread -lc

hpmdd78# perl -MExtUtils::Embed -le ccopts
-D_POSIX_C_SOURCE=199506L -D_REENTRANT -Ae -D_HPUX_SOURCE -Wl,+vnocompatwarnings +DAportable +DS2.0 +Z -DUSE_SITECUSTOMIZE -DNO_HASH_SEED -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/opt/perl_32/lib/5.8.8/PA-RISC1.1-thread-multi/CORE
hpmdd78# perl -MExtUtils::Embed -le ldopts
-Wl,-E -Wl,-B,deferred /opt/perl_32/lib/5.8.8/PA-RISC1.1-thread-multi/auto/DynaLoader/DynaLoader.a -L/opt/perl_32/lib/5.8.8/PA-RISC1.1-thread-multi/CORE -lperl -lcl -lcres -lnsl -lnm -lmalloc -ldld -lm -lcrypt -lsec -lpthread -lc
Syed Madar J S
Frequent Advisor

Re: perl points to incorrect @INC when embedded in a "C" code

Thanks Everyone