Calling External DLL functions in Perl using Inline

Calling External DLL functions in Perl using Inline

am 11.07.2005 15:47:12 von Sankaran

Hello

I am trying to call a DLL function from Perl using Inline as follows

use Inline C =3D> DATA =3D>
LIBS =3D> '-lInlinetestLib';
greet();

__END__
__C__
#include "InlinetestLib.h"
void greet(){
int nId =3D fnInlinetestLib();
printf ("%d", nId);
printf("Hello, world from Perl Inline, By Sankaran\n");}
Where:
InlinetestLib is a test dll with 1 exported function fnInlinetestLib()

I am getting the following error while I am trying to run this;
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1>Pe rl Hello.Pl

Microsoft (R) Program Maintenance Utility Version 6.00.9782.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

mkdir blib
mkdir blib\lib
mkdir blib\arch
mkdir blib\arch\auto
mkdir blib\arch\auto\Hello_Pl_74c2
mkdir blib\lib\auto
mkdir blib\lib\auto\Hello_Pl_74c2
D:\Perl\bin\Perl.exe -ID:\Perl\lib -ID:\Perl\lib
D:\Perl\lib\ExtUtils/xs
ubpp -typemap D:\Perl\lib\ExtUtils\typemap Hello_Pl_74c2.xs >
Hello_Pl_74c2.xsc
&& D:\Perl\bin\Perl.exe -ID:\Perl\lib -ID:\Perl\lib
-MExtUtils::Command -e mv H
ello_Pl_74c2.xsc Hello_Pl_74c2.c
cl -c
-IE:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1 -O1 -M
D -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT
-DPERL_IMPLICIT_CONT
EXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX -O1 -MD -DNDEBUG
-DVERSION=3D\"
000\" -DXS_VERSION=3D\"0.00\" -ID:\Perl\lib\CORE Hello_Pl_74c2.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

Hello_Pl_74c2.c
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(1=
5)
:
error C2054: expected '(' to follow 'class'
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(1=
5)
:
error C2085: 'CInlinetestLib' : not in formal parameter list
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(1=
5)
:
error C2143: syntax error : missing ';' before '{'
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.

A problem was encountered while attempting to compile and install your
Inline
C code. The command that failed was:
nmake > out.make 2>&1

The build directory was:
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1\_I nline\build\Hel=
lo_Pl
_74c2

To debug the problem, cd to the build directory, and inspect the output
files.

at Hello.Pl line 0
INIT failed--call queue aborted.

But when I am trying a sample which I got from net, it is running fine.
The example which I tried is
use Inline C =3D> DATA =3D>
LIBS =3D> '-luser32',
PREFIX =3D> 'my_';
MessageBoxA('Inline Message Box', 'Just Another Perl Hacker');


__END__
__C__
#include
int my_MessageBoxA(char* Caption, char* Text) {
return MessageBoxA(0, Text, Caption, 0);
}

This is displaying a MessageBox as the output.

My doubts are;
=B7 Where should be the .h file contains the exported interface?
=B7 Path of LIB file and DLL?
=B7 Is it necessary to provide my DLL / LIB path in the environment
PATH variable? (I have already added the DLL / LIB / .H file path in
the PATH variable)

Kindly provide the guidelines incase if any, so that it will help me.

Regards,
Sankaran

Re: Calling External DLL functions in Perl using Inline

am 11.07.2005 21:18:05 von Sisyphus

"Sankaran" wrote in message
news:1121089632.521430.234120@f14g2000cwb.googlegroups.com.. .
Hello

I am trying to call a DLL function from Perl using Inline as follows

use Inline C => DATA =>
LIBS => '-lInlinetestLib';
greet();

__END__
__C__
#include "InlinetestLib.h"
void greet(){
int nId = fnInlinetestLib();
printf ("%d", nId);
printf("Hello, world from Perl Inline, By Sankaran\n");}


Where:
InlinetestLib is a test dll with 1 exported function fnInlinetestLib()

I am getting the following error while I am trying to run this;

[snip]

A problem was encountered while attempting to compile and install your
Inline
C code. The command that failed was:
nmake > out.make 2>&1

The build directory was:
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1\_I nline\build\Hell
o_Pl
_74c2

To debug the problem, cd to the build directory, and inspect the output
files.

at Hello.Pl line 0
INIT failed--call queue aborted.

But when I am trying a sample which I got from net, it is running fine.
The example which I tried is
use Inline C => DATA =>
LIBS => '-luser32',
PREFIX => 'my_';
MessageBoxA('Inline Message Box', 'Just Another Perl Hacker');


__END__
__C__
#include
int my_MessageBoxA(char* Caption, char* Text) {
return MessageBoxA(0, Text, Caption, 0);
}

This is displaying a MessageBox as the output.

My doubts are;
· Where should be the .h file contains the exported interface?
· Path of LIB file and DLL?
· Is it necessary to provide my DLL / LIB path in the environment
PATH variable? (I have already added the DLL / LIB / .H file path in
the PATH variable)

Kindly provide the guidelines incase if any, so that it will help me.

Regards,
Sankaran
------------------------------------------------------------ ----------------
-----

You can specify the location of LIBS (InlinetestLib.lib) and INC
(InlinetestLib.h) as below.
Note that you need to link to the import lib 'InlinetestLib.lib' (just as
you linked to user32.lib in the above example) because MSVC++ is incapable
of linking directly to the dll. If you don't have an import lib, then you'll
need to make one.

You don't need to provide the path to user32.lib because that gets found
automatically - and you also don't need to tell the compiler where windows.h
is, because that too gets found ok. But you will need to tell the compiler
where InlinetestLib.lib is located (hence the
-L/path/to/your_import_lib below), and you'll need to tell the compiler
where InlinetestLib.h is located (hence the
-I/path/to/your_include_file below).

You can use the layout you used above for your Inline script if you like.
I've provided a slightly different layout below, because that's the layout
I'm more familiar with. (I've also specified BUILD_NOISY so that you see
what's happening as the script compiles the first time you run it.)

use warnings;

use Inline C => Config =>
LIBS => '-L/path/to/your_import_lib -lInlinetestLib',
INC => '-I/path/to/your_include_file',
BUILD_NOISY => 1;

use Inline C => <<'EOC';

#include "InlinetestLib.h"
void greet(){
int nId = fnInlinetestLib();
printf ("%d", nId);
printf("Hello, world from Perl Inline, By Sankaran\n");
}

EOC

greet();

__END__

Cheers,
Rob

Re: Calling External DLL functions in Perl using Inline

am 12.07.2005 08:37:52 von Sankaran

Hello

I am getting the following out put
______________________________________
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1>pe rl Hello.Pl
Starting Build Prepocess Stage
Finished Build Prepocess Stage

Starting Build Parse Stage
Finished Build Parse Stage

Starting Build Glue 1 Stage
Finished Build Glue 1 Stage

Starting Build Glue 2 Stage
Finished Build Glue 2 Stage

Starting Build Glue 3 Stage
Finished Build Glue 3 Stage

Starting Build Compile Stage
Starting "perl Makefile.PL" Stage
Note (probably harmless): No library found for '-lInlinetestLib'
Writing Makefile for Hello_Pl_5dd0
Finished "perl Makefile.PL" Stage

Starting "make" Stage

Microsoft (R) Program Maintenance Utility Version 6.00.9782.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

D:\Perl\bin\Perl.exe -ID:\Perl\lib -ID:\Perl\lib
D:\Perl\lib\ExtUtils/xs
ubpp -typemap D:\Perl\lib\ExtUtils\typemap Hello_Pl_5dd0.xs >
Hello_Pl_5dd0.xsc
&& D:\Perl\bin\Perl.exe -ID:\Perl\lib -ID:\Perl\lib
-MExtUtils::Command -e mv H
ello_Pl_5dd0.xsc Hello_Pl_5dd0.c
cl -c
-IE:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1 -I\E:\
Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1 -O1 -MD -DNDEBUG
-DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT
_SYS -DPERL_MSVCRT_READFIX -O1 -MD -DNDEBUG -DVERSION=\"0.00\"
-DXS_VERSIO
N=\"0.00\" -ID:\Perl\lib\CORE Hello_Pl_5dd0.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

Hello_Pl_5dd0.c
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15)
:
error C2054: expected '(' to follow 'class'
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15)
:
error C2085: 'CInlinetestLib' : not in formal parameter list
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15)
:
error C2143: syntax error : missing ';' before '{'
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.

A problem was encountered while attempting to compile and install your
Inline
C code. The command that failed was:
nmake

The build directory was:
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1\_I nline\build\Hello_Pl
_5dd0

To debug the problem, cd to the build directory, and inspect the output
files.

at Hello.Pl line 8
BEGIN failed--compilation aborted at Hello.Pl line 17.
________________________________________________________
for the below modified program...
use warnings;

use Inline C => Config =>
LIBS => '-L\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest 1
-lInlinetestLib',
INC => '-I\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest 1',
BUILD_NOISY => 1;

use Inline C => <<'EOC';

#include "InlinetestLib.h"
void greet(){
int nId = fnInlinetestLib();
printf ("%d", nId);
printf("Hello, world from Perl Inline, By Sankaran\n");

}
EOC
greet();
__END__
________________________________________________________
I have modified your program.
Any clue?

Regards,
Sankaran

Re: Calling External DLL functions in Perl using Inline

am 13.07.2005 05:26:59 von Sisyphus

"Sankaran" wrote in message
news:1121150272.130243.17400@g14g2000cwa.googlegroups.com...

> Starting Build Compile Stage
> Starting "perl Makefile.PL" Stage
> Note (probably harmless): No library found for '-lInlinetestLib'

Nope - it's not harmless. InlinetestLib.lib needs to be found. Where is it ?
(I think it might have been created when you built the dll ... but I'm not
sure about that.)
If you don't have it, can you tell me how the dll was built - ie which
command(s) did you run.

[snip]

> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
> 80x86
> Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
>
> Hello_Pl_5dd0.c
>
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15
)
> :
> error C2054: expected '(' to follow 'class'
>
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15
)
> :
> error C2085: 'CInlinetestLib' : not in formal parameter list
>
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15
)
> :
> error C2143: syntax error : missing ';' before '{'
> NMAKE : fatal error U1077: 'cl' : return code '0x2'
> Stop.

The compiler doesn't like the way InlineTestLib.h is written. Did you get
the same problems when you built the dll ?

> ________________________________________________________
> for the below modified program...
> use warnings;
>
> use Inline C => Config =>
> LIBS => '-L\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest 1
> -lInlinetestLib',

The location is incorrectly specified. Perhaps that's why the file can't be
found. Should be:
LIBS => '-LE:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1

> INC => '-I\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest 1',

Change to:
INC => '-IE:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1 ',

> BUILD_NOISY => 1;
>
> use Inline C => <<'EOC';
>
> #include "InlinetestLib.h"
> void greet(){
> int nId = fnInlinetestLib();
> printf ("%d", nId);
> printf("Hello, world from Perl Inline, By Sankaran\n");
>
> }
> EOC
> greet();
> __END__
> ________________________________________________________
>

Cheers,
Rob

Re: Calling External DLL functions in Perl using Inline

am 14.07.2005 08:30:31 von Brian McCauley

Sankaran wrote:
> E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15)
> :
> error C2054: expected '(' to follow 'class'
> E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyThest1\I nlinetestLib.h(15)

This sounds like you are trying to compile C++ source with the compiler
in C mode.

Re: Calling External DLL functions in Perl using Inline

am 14.07.2005 09:40:21 von Sisyphus

"Brian McCauley" wrote in message
news:db50q6$ubm$1@redhat2.bham.ac.uk...
> Sankaran wrote:
> >
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15
)
> > :
> > error C2054: expected '(' to follow 'class'
> >
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyThest1\I nlinetestLib.h(1
5)
>
> This sounds like you are trying to compile C++ source with the compiler
> in C mode.
>

Aaah - that being the case, I think the fix is to install Inline::CPP from
cpan, and then in the script 'use Inline CPP' insteas of 'use Inline C'.

Iirc, there's a glitch in getting Inline::CPP to work with VC6. It's simple
to fix. At about line 44 of CPP.pm you can find:

#ifndef bool

Immediately above that line insert:

#include

Cheers,
Rob

Re: Calling External DLL functions in Perl using Inline

am 21.07.2005 21:38:23 von ben.sommer

Sisyphus wrote:
> "Sankaran" wrote in message
> news:1121150272.130243.17400@g14g2000cwa.googlegroups.com...
>
> > Starting Build Compile Stage
> > Starting "perl Makefile.PL" Stage
> > Note (probably harmless): No library found for '-lInlinetestLib'
>
> Nope - it's not harmless. InlinetestLib.lib needs to be found. Where is it ?
> (I think it might have been created when you built the dll ... but I'm not
> sure about that.)
> If you don't have it, can you tell me how the dll was built - ie which
> command(s) did you run.
>
> [snip]
>
> > Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
> > 80x86
> > Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
> >
> > Hello_Pl_5dd0.c
> >
> E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15
> )
> > :
> > error C2054: expected '(' to follow 'class'
> >
> E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15
> )
> > :
> > error C2085: 'CInlinetestLib' : not in formal parameter list
> >
> E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\In linetestLib.h(15
> )
> > :
> > error C2143: syntax error : missing ';' before '{'
> > NMAKE : fatal error U1077: 'cl' : return code '0x2'
> > Stop.
>
> The compiler doesn't like the way InlineTestLib.h is written. Did you get
> the same problems when you built the dll ?
>
> > ________________________________________________________
> > for the below modified program...
> > use warnings;
> >
> > use Inline C => Config =>
> > LIBS => '-L\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest 1
> > -lInlinetestLib',
>
> The location is incorrectly specified. Perhaps that's why the file can't be
> found. Should be:
> LIBS => '-LE:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1
>
> > INC => '-I\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest 1',
>
> Change to:
> INC => '-IE:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1 ',
>
> > BUILD_NOISY => 1;
> >
> > use Inline C => <<'EOC';
> >
> > #include "InlinetestLib.h"
> > void greet(){
> > int nId = fnInlinetestLib();
> > printf ("%d", nId);
> > printf("Hello, world from Perl Inline, By Sankaran\n");
> >
> > }
> > EOC
> > greet();
> > __END__
> > ________________________________________________________
> >
>
> Cheers,
> Rob


Hi All.

I'm just wondering how this problem resolved for you, Sankaran. I have
the (almost) exact same problem, though my environment is cygwin+gcc.
The user32.dll example from the Inline docs works flawlessly for me as
well. Also, for my application, any conceivable permutation of the INC
or LIBS directives (and windows/cygwin LIB/INC/PATH environment
variables) always results in this:

Note (probably harmless): No library found for '-lMyLib'

Pretty frustrating!


Thanks for reading,
--
Ben Sommer
Senior Technology Officer
Eastern Nazarene College
23 East Elm Ave
Quincy, MA 02170

Re: Calling External DLL functions in Perl using Inline

am 22.07.2005 11:13:15 von Sisyphus


>
>
> Hi All.
>
> I'm just wondering how this problem resolved for you, Sankaran. I have
> the (almost) exact same problem, though my environment is cygwin+gcc.

Brian McCauley suggested the specific problem to which you allude was the
result of trying to process C++ source code with the compiler in C mode. If
that's so (and I've seen a couple of other posts suggesting the same thing)
then I think the solution would be to either convert the C++ source to C, or
use Inline::CPP.

With gcc, you need to be compiling C++ code with g++, not gcc - so if,
during the installation of Inline::CPP, you're prompted for which compiler
to use, make sure that g++ is specified.

So ..... I guess the advice is for you to use Inline::CPP if the source is
C++. If the source is C and you're still getting those errors, then let us
know.

> The user32.dll example from the Inline docs works flawlessly for me as
> well.

That's C code, so one would expect no problem there.

>Also, for my application, any conceivable permutation of the INC
> or LIBS directives (and windows/cygwin LIB/INC/PATH environment
> variables) always results in this:
>
> Note (probably harmless): No library found for '-lMyLib'
>

Sometimes that warning actually *is* harmless - I see it from time to time,
but I only ever take notice of it whenever 'MyLib' is not found.

If the lib is not being found, have you tried:
LIBS => '-L/full_path/to_MyLib -lMyLib',

If you specify '-lMyLib', will gcc find a file called 'MyLib.a', or will it
find only a file named 'libMyLib.a' ? (I think it will find either, but you
might check on that in case there's a problem there.)

Let us know how you get on with this.

Cheers,
Rob

Re: Calling External DLL functions in Perl using Inline

am 22.07.2005 18:01:09 von ben.sommer

Sisyphus wrote:
>
> >
> >
> > Hi All.
> >
> > I'm just wondering how this problem resolved for you, Sankaran. I have
> > the (almost) exact same problem, though my environment is cygwin+gcc.
>
> Brian McCauley suggested the specific problem to which you allude was the
> result of trying to process C++ source code with the compiler in C mode. If
> that's so (and I've seen a couple of other posts suggesting the same thing)
> then I think the solution would be to either convert the C++ source to C, or
> use Inline::CPP.
>
> With gcc, you need to be compiling C++ code with g++, not gcc - so if,
> during the installation of Inline::CPP, you're prompted for which compiler
> to use, make sure that g++ is specified.
>
> So ..... I guess the advice is for you to use Inline::CPP if the source is
> C++. If the source is C and you're still getting those errors, then let us
> know.
>
> > The user32.dll example from the Inline docs works flawlessly for me as
> > well.
>
> That's C code, so one would expect no problem there.
>
> >Also, for my application, any conceivable permutation of the INC
> > or LIBS directives (and windows/cygwin LIB/INC/PATH environment
> > variables) always results in this:
> >
> > Note (probably harmless): No library found for '-lMyLib'
> >
>
> Sometimes that warning actually *is* harmless - I see it from time to time,
> but I only ever take notice of it whenever 'MyLib' is not found.
>
> If the lib is not being found, have you tried:
> LIBS => '-L/full_path/to_MyLib -lMyLib',

Oh yes. Like I said, I've tried every concveivable permutation.

> If you specify '-lMyLib', will gcc find a file called 'MyLib.a', or will it
> find only a file named 'libMyLib.a' ? (I think it will find either, but you
> might check on that in case there's a problem there.)
>
> Let us know how you get on with this.

A gracious response Rob. Many thanks.

Well, you pointed out an inconsistency: my .lib and .dll files don't
have .a extension. I gratuitously added one and the "No library found"
error dissapeared. How annoying. I grokked the gcc man page and see
what you mean about library file extensions (and prepensions). I'll
send a note to the Inline::C author asking him to include a caveat in
the section of his docs that talks about DLLs.

Cygwin is sometimes confusing, kinda windows, kinda unix. Sometimes
case sensitive, sometimes not.

Best,

--
Ben Sommer
Senior Technology Officer
Eastern Nazarene College
23 East Elm Ave
Quincy, MA 02170

Re: Calling External DLL functions in Perl using Inline

am 22.07.2005 22:31:55 von ben.sommer

ben.sommer@enc.edu wrote:
> Sisyphus wrote:
> >
> > >
> > >
> > > Hi All.
> > >
> > > I'm just wondering how this problem resolved for you, Sankaran. I have
> > > the (almost) exact same problem, though my environment is cygwin+gcc.
> >
> > Brian McCauley suggested the specific problem to which you allude was the
> > result of trying to process C++ source code with the compiler in C mode. If
> > that's so (and I've seen a couple of other posts suggesting the same thing)
> > then I think the solution would be to either convert the C++ source to C, or
> > use Inline::CPP.
> >
> > With gcc, you need to be compiling C++ code with g++, not gcc - so if,
> > during the installation of Inline::CPP, you're prompted for which compiler
> > to use, make sure that g++ is specified.
> >
> > So ..... I guess the advice is for you to use Inline::CPP if the source is
> > C++. If the source is C and you're still getting those errors, then let us
> > know.
> >
> > > The user32.dll example from the Inline docs works flawlessly for me as
> > > well.
> >
> > That's C code, so one would expect no problem there.
> >
> > >Also, for my application, any conceivable permutation of the INC
> > > or LIBS directives (and windows/cygwin LIB/INC/PATH environment
> > > variables) always results in this:
> > >
> > > Note (probably harmless): No library found for '-lMyLib'
> > >
> >
> > Sometimes that warning actually *is* harmless - I see it from time to time,
> > but I only ever take notice of it whenever 'MyLib' is not found.
> >
> > If the lib is not being found, have you tried:
> > LIBS => '-L/full_path/to_MyLib -lMyLib',
>
> Oh yes. Like I said, I've tried every concveivable permutation.
>
> > If you specify '-lMyLib', will gcc find a file called 'MyLib.a', or will it
> > find only a file named 'libMyLib.a' ? (I think it will find either, but you
> > might check on that in case there's a problem there.)
> >
> > Let us know how you get on with this.
>
> A gracious response Rob. Many thanks.
>
> Well, you pointed out an inconsistency: my .lib and .dll files don't
> have .a extension. I gratuitously added one and the "No library found"
> error dissapeared. How annoying. I grokked the gcc man page and see
> what you mean about library file extensions (and prepensions). I'll
> send a note to the Inline::C author asking him to include a caveat in
> the section of his docs that talks about DLLs.
>
> Cygwin is sometimes confusing, kinda windows, kinda unix. Sometimes
> case sensitive, sometimes not.

Well, cygwin is the problem, though I might also fault the Inline::C
documentation. Taking that DLL example from the Inline::C cookbook...

http://search.cpan.org/~ingy/Inline-0.44/C/C-Cookbook.pod#Wi n32

use Inline C => DATA =>
LIBS => '-luser32';

$text = "@ARGV" || 'Inline.pm works with MSWin32. Scary...';

WinBox('Inline Text Box', $text);

__END__
__C__

#include

int WinBox(char* Caption, char* Text) {
return MessageBoxA(0, Text, Caption, 0);
}


That config directive "LIBS => '-luser32'" looks pretty key right? It
says 'go call "user32.dll", right? Wrong. It does nothing. Remove it
and the code compiles and runs the same. Its the windows.h include file
that makes this example - and probably all Win32 dlls - work under
cygwin, thanks to all the hand-rolled header files in
/usr/include/w32api. I'd love to hear from people using Inline::C under
cygwin with gcc and a _custom_ DLL file. How do you manage to link it.
How do are you able to include your own header files? Please prove me
wrong! I'd even listen to people having success with ActiveState perl
and Visual Studio (ugh). Off to post to the cygwin list...

Best,
--
Ben Sommer
Senior Technology Officer
Eastern Nazarene College
23 East Elm Ave
Quincy, MA 02170

Re: Calling External DLL functions in Perl using Inline

am 23.07.2005 02:20:09 von Sisyphus

wrote

> Taking that DLL example from the Inline::C cookbook...
>
> http://search.cpan.org/~ingy/Inline-0.44/C/C-Cookbook.pod#Wi n32
>
> use Inline C => DATA =>
> LIBS => '-luser32';
>
> $text = "@ARGV" || 'Inline.pm works with MSWin32. Scary...';
>
> WinBox('Inline Text Box', $text);
>
> __END__
> __C__
>
> #include
>
> int WinBox(char* Caption, char* Text) {
> return MessageBoxA(0, Text, Caption, 0);
> }
>
>
> That config directive "LIBS => '-luser32'" looks pretty key right? It
> says 'go call "user32.dll", right? Wrong. It does nothing. Remove it
> and the code compiles and runs the same.

No - I think that LIBS directive is saying "link to libuser32.a" - which you
should find in Cygwin's gcc/lib folder.
I think that script builds ok when you remove the LIBS directive because
libuser32.a is linked to automatically. That automatic linking is built in
by the ExtUtils modules. To verify, insert the following at the top of the
script:

use Inline C => Config =>
BUILD_NOISY => 1;

Then make some change to the C code in that script (to force it to rebuild -
add or delete some white space is sufficient).

Then re-run the script. Somewhere in the output you should see 'libuser32.a'
mentioned (along with a heap of other libs).

> Its the windows.h include file
> that makes this example - and probably all Win32 dlls - work under
> cygwin, thanks to all the hand-rolled header files in
> /usr/include/w32api.

You'll possibly find you don't even have to specifically include windows.h
either. Your Inline::C code will automatically include 'perl.h' and that
might lead to the inclusion of 'windows.h'. On my perls that's the way it
is, anyway. 'perl.h' includes 'win32.h' which includes 'windows.h'. It might
be different under Cygwin.

> I'd love to hear from people using Inline::C under
> cygwin with gcc and a _custom_ DLL file.
> How do you manage to link it.

To link directly to a dll (which is possible with gcc, but not with
Microsoft compilers) you specify the 'MYEXTLIB' config directive - eg:

MYEXTLIB => "/full_path/to_dll/MyDLL.dll",

> How do are you able to include your own header files?

You just list them as you would in normal C code. You can use the 'INC'
config directive to specify the directory that they are in (if they're not
already in some standard location):

INC => "-I/full_path/to_folder/that_contains/my_includes",

> Please prove me
> wrong! I'd even listen to people having success with ActiveState perl
> and Visual Studio (ugh).

I use gcc (MinGW) most of the time - but that's using 'gcc' in a native
Win32 environment - not in a Cygwin environment. I also use MSVC++ 7.0
(.NET) which is a very good compiler - though, for me, a little cumbersome
to use. I prefer to use MinGW as I find I'm a lot more comfortable with it.
I would never use Cygwin - for various reasons (most of which don't apply to
everybody .... or do I mean "anybody" ? :-).

>Off to post to the cygwin list...
>

For Inline::C questions, the best forum is the Inline mailing list. (See
http://lists.perl.org/index.cgi :-)

Cheers,
Rob

Re: Calling External DLL functions in Perl using Inline

am 28.07.2005 17:14:45 von ben.sommer

Sisyphus wrote:
> wrote
>
> > Taking that DLL example from the Inline::C cookbook...
> >
> > http://search.cpan.org/~ingy/Inline-0.44/C/C-Cookbook.pod#Wi n32
> >
> > use Inline C => DATA =>
> > LIBS => '-luser32';
> >
> > $text = "@ARGV" || 'Inline.pm works with MSWin32. Scary...';
> >
> > WinBox('Inline Text Box', $text);
> >
> > __END__
> > __C__
> >
> > #include
> >
> > int WinBox(char* Caption, char* Text) {
> > return MessageBoxA(0, Text, Caption, 0);
> > }
> >
> >
> > That config directive "LIBS => '-luser32'" looks pretty key right? It
> > says 'go call "user32.dll", right? Wrong. It does nothing. Remove it
> > and the code compiles and runs the same.
>
> No - I think that LIBS directive is saying "link to libuser32.a" - which you
> should find in Cygwin's gcc/lib folder.
> I think that script builds ok when you remove the LIBS directive because
> libuser32.a is linked to automatically. That automatic linking is built in
> by the ExtUtils modules. To verify, insert the following at the top of the
> script:
>
> use Inline C => Config =>
> BUILD_NOISY => 1;
>
> Then make some change to the C code in that script (to force it to rebuild -
> add or delete some white space is sufficient).
>
> Then re-run the script. Somewhere in the output you should see 'libuser32.a'
> mentioned (along with a heap of other libs).
>
> > Its the windows.h include file
> > that makes this example - and probably all Win32 dlls - work under
> > cygwin, thanks to all the hand-rolled header files in
> > /usr/include/w32api.
>
> You'll possibly find you don't even have to specifically include windows.h
> either. Your Inline::C code will automatically include 'perl.h' and that
> might lead to the inclusion of 'windows.h'. On my perls that's the way it
> is, anyway. 'perl.h' includes 'win32.h' which includes 'windows.h'. It might
> be different under Cygwin.
>
> > I'd love to hear from people using Inline::C under
> > cygwin with gcc and a _custom_ DLL file.
> > How do you manage to link it.
>
> To link directly to a dll (which is possible with gcc, but not with
> Microsoft compilers) you specify the 'MYEXTLIB' config directive - eg:
>
> MYEXTLIB => "/full_path/to_dll/MyDLL.dll",
>
> > How do are you able to include your own header files?
>
> You just list them as you would in normal C code. You can use the 'INC'
> config directive to specify the directory that they are in (if they're not
> already in some standard location):
>
> INC => "-I/full_path/to_folder/that_contains/my_includes",
>
> > Please prove me
> > wrong! I'd even listen to people having success with ActiveState perl
> > and Visual Studio (ugh).
>
> I use gcc (MinGW) most of the time - but that's using 'gcc' in a native
> Win32 environment - not in a Cygwin environment. I also use MSVC++ 7.0
> (.NET) which is a very good compiler - though, for me, a little cumbersome
> to use. I prefer to use MinGW as I find I'm a lot more comfortable with it.
> I would never use Cygwin - for various reasons (most of which don't apply to
> everybody .... or do I mean "anybody" ? :-).
>
> >Off to post to the cygwin list...
> >
>
> For Inline::C questions, the best forum is the Inline mailing list. (See
> http://lists.perl.org/index.cgi :-)
>
> Cheers,
> Rob

Thanks so much, Rob. I'll be dilligent in trying all your suggestions.

Best,
~Ben Sommer