K
Kenjis Kaan
Have anyone tried hooking perl to external C libraries? I am trying
to port some code in C into a module (ie. DLL) which can then be
called from Perl.
I did the usual stuffs with h2xs to generate the Mytest.xs/Mytest.pm
and support environment.
As a Test wanted to see how Mytest.xs file works so I proceed to
modify. I wanted first to see that it can pull in the headers ok.
so I added to Mytest.xs
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#ifdef __cplusplus
}
#endif
---------------------------------------------------------------
Then of course the perl Makefile.pl to generate *.c etc
Then tried to use MSVC6 to compile it, everything is ok except for
malloc.h
Here is what came out from NMAKE
E:\var\h2xs\Mytest>nmake
Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.
cp Mytest.pm blib\lib\Mytest.pm
cp mytest.pl blib\lib\mytest.pl
C:\Perl\bin\perl.exe -IC:\Perl\lib -IC:\Perl\lib
C:\Perl\lib\ExtUtils/xs
ubpp -typemap C:\Perl\lib\ExtUtils\typemap Mytest.xs > Mytest.xsc &&
C:\Perl\bi
n\perl.exe -IC:\Perl\lib -IC:\Perl\lib -MExtUtils::Command -e mv
Mytest.xsc Myte
st.c
Please specify prototyping behavior for Mytest.xs (see perlxs manual)
cl -c -nologo -O1 -MD -Zi -DNDEBUG -DWIN32 -D_CONSOLE
-DNO_STRICT -DHAV
E_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DPERL_MSVCRT_READFIX -
O1 -MD -Zi -DNDEBUG -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\"
-IC:\Perl\lib\
CORE Mytest.c
Mytest.c
C:\VC\VC98\INCLUDE\malloc.h(106) : error C2059: syntax error : '('
C:\VC\VC98\INCLUDE\malloc.h(107) : error C2059: syntax error : '('
C:\VC\VC98\INCLUDE\malloc.h(108) : error C2059: syntax error : '('
NMAKE : fatal error U1077: 'C:\WINNT\system32\cmd.exe' : return code
'0x2'
Stop.
-------------------------------------------------------------------------------
I opened up malloc.h in an editor and this is what I see at those 3
lines (106,107,108)
_CRTIMP void __cdecl free(void *);
_CRTIMP void * __cdecl malloc(size_t);
_CRTIMP void * __cdecl realloc(void *, size_t);
to port some code in C into a module (ie. DLL) which can then be
called from Perl.
I did the usual stuffs with h2xs to generate the Mytest.xs/Mytest.pm
and support environment.
As a Test wanted to see how Mytest.xs file works so I proceed to
modify. I wanted first to see that it can pull in the headers ok.
so I added to Mytest.xs
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#ifdef __cplusplus
}
#endif
---------------------------------------------------------------
Then of course the perl Makefile.pl to generate *.c etc
Then tried to use MSVC6 to compile it, everything is ok except for
malloc.h
Here is what came out from NMAKE
E:\var\h2xs\Mytest>nmake
Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.
cp Mytest.pm blib\lib\Mytest.pm
cp mytest.pl blib\lib\mytest.pl
C:\Perl\bin\perl.exe -IC:\Perl\lib -IC:\Perl\lib
C:\Perl\lib\ExtUtils/xs
ubpp -typemap C:\Perl\lib\ExtUtils\typemap Mytest.xs > Mytest.xsc &&
C:\Perl\bi
n\perl.exe -IC:\Perl\lib -IC:\Perl\lib -MExtUtils::Command -e mv
Mytest.xsc Myte
st.c
Please specify prototyping behavior for Mytest.xs (see perlxs manual)
cl -c -nologo -O1 -MD -Zi -DNDEBUG -DWIN32 -D_CONSOLE
-DNO_STRICT -DHAV
E_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DPERL_MSVCRT_READFIX -
O1 -MD -Zi -DNDEBUG -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\"
-IC:\Perl\lib\
CORE Mytest.c
Mytest.c
C:\VC\VC98\INCLUDE\malloc.h(106) : error C2059: syntax error : '('
C:\VC\VC98\INCLUDE\malloc.h(107) : error C2059: syntax error : '('
C:\VC\VC98\INCLUDE\malloc.h(108) : error C2059: syntax error : '('
NMAKE : fatal error U1077: 'C:\WINNT\system32\cmd.exe' : return code
'0x2'
Stop.
-------------------------------------------------------------------------------
I opened up malloc.h in an editor and this is what I see at those 3
lines (106,107,108)
_CRTIMP void __cdecl free(void *);
_CRTIMP void * __cdecl malloc(size_t);
_CRTIMP void * __cdecl realloc(void *, size_t);