Iam linking C/C++ lib with Perl h2xs XSUBs.
I have done the following:.
1. Create a new directory called Mytest2. In the Mytest2 directory, create another directory called mylib,..
2. Here we'll create some files that will generate a test library. These will include a C source file and a header file. We'll also create a Makefile.PL in this directory..
use ExtUtils::MakeMaker;
$verbose = 1;
WriteMakefile(
NAME => 'MyTest::mylib',
SKIP => qw(all static static_lib dynamic dynamic_lib),
clean => {'FILES' => 'mibmylib$(LIB_EXT)'},
);
sub MY::top_targets {
'
#all :: static
#pure_all ::static
static :: libmylib$(LIB_EXT)
libmylib$(LIB_EXT): $(O_FILES)
$(AR) cr libmylib$(LIB_EXT) $(O_FILES)
$(AR) -nologo -out:libmylib$(LIB_EXT) $(O_FILES)
';
}
3. Then I do and h2xs c:\per\bin> h2xs –O -n Mytest2 ./Mytest2/mylib/mylib.h
4.I get Makefile.pl generated from the above execution
5. Now I need to specify the subdirectory mylib that generates library in it.
I need to specify 'MYEXTLIB'
=> 'mylib/libmylib$(LIB_EXT)', in the Makefile.pl
use 5.010000;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Mytest2',
VERSION_FROM => 'lib/Mytest2.pm', # finds $VERSION
PREREQ_PM => {}, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Mytest2.pm', # retrieve abstract from module
AUTHOR => 'A. U. Thor') : ()),
LIBS =>
'', # e.g., '-lm'
DEFINE => '', # e.g., '- DHAVE_SOMETHING'
INC => '-I.', # e.g., '-I. - I/usr/include/other'
'MYEXTLIB' => 'mylib/libmylib$(LIB_EXT)',
# Un-comment this if you add C files to link with later:
OBJECT => '$(O_FILES)', # link all the C files too
);
sub MY::postamble {
'
$(MYEXTLIB): mylib/Makefile
cd mylib && $(MAKE) $(PASSTHRU)
';
}
6. Fix the MANIFEST file so that it accurately reflects the contents of our extension
mylib/Makfile.PL
mylib/mylib.h
mylib/mylib.c
7.Also did relvant changes in .Xs file and .Pm file.
8.In the cmd prompt I execute Perl Makefile.pl
9.when I say nmake on the cmd prompt I get the following error msg:
C:\Perl\bin\MyTest2>perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for MyTest::mylib
Writing Makefile for Mytest2
C:\Perl\bin\MyTest2>nmake
Microsoft (R) Program Maintenance Utility Version 1.50 Copyright (c) Microsoft Corp 1988-94. All rights reserved.
cp lib/Mytest2.pm blib\lib\Mytest2.pm
AutoSplitting blib\lib\Mytest2.pm (blib\lib\auto\Mytest2) cd mylib && nmake
Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
cl -c -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_ST RICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT _CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -MD -Zi -DNDEBUG -O1 -DVERSION=\"\" -DXS_VERSION=\"\" "-IC:\Perl\lib\CORE" mylib.c
mylib.c
lib cr libmylib.lib mylib.obj
Microsoft (R) Library Manager Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
LIB : fatal error LNK1181: cannot open input file 'cr'
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\lib.EXE"' : return code '0x49d' Stop.
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x2'
Stop.
The error seems to be in the makefile which I am not able to debug.
Can u please let me know where I m going wrong in the Makefile

In reply to linking C/C++ lib with Perl h2xs XSUBs. by anupama

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.