[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Dynaloader, CW and Math64Lib



mask@hrnet.fr writes:
>I would like to build a C library using Code Warrior 9(IDE 1.6):

Wow! Those French are really pushing the state of the art in MacPerl lately :-)

>For test, I make the following:
>
>1.I have a small source code in C: 
>>  int test (int x) {
>>      return (2*x);
>>  }

That already won't work. The C functions that Perl can call need to follow
a fairly strict interface, so you should write an .xs file and pass it through
xsubpp.

>compile as a Library named TestCLib in Preferences:PPC Project, without
>any
>others libs in the project (this not build a Math64Lib, but a CW Lib,
>the problem comes from here).

Dynamic loading works only for shared libraries (the common term for what you
call a "Math64Lib" is "shared library").

>Save these Lib in folder
>lib:MacPPC:auto:TestCLib:
>of my new MacPerl 5.1.4b2.

Fine.

>2.TestCLib.pm and test.pl are:
>>  package TestCLib;
>>  require Dynaloader;
>>  @ISA = qw(DynaLoader);

You also need to require Exporter and include it in @ISA.

>>  @EXPORT = qw(test);
>>
>>  bootstrap TestCLib;
>>  1;
>>  __END__

Fine.

>>  #!/perl -w
>>  use TestCLib;
>>  $var = test(5);
>>  print ">> $var\n";
>>  __END__
>until now, I think all is correct.

Fine.

>3.The test.pl script execution return:
>
>>  # Can't load 'Hard Drive:MacPerl 5.1.4b2:lib:MacPPC:auto:TestCLib:TestCLib'
\
>>  for module TestCLib: # DynaLoader error [-2806, TestCLib].
>>  File 'Hard Drive:MacPerl 5.1.4b2:lib:Dynaloader.pm'; Line 172
>>
>>
>>  File 'Dev:Pseudo'; Line 2
>>  # BEGIN failed--compilation aborted.
>>  File '<AppleEvent>'; Line 2
>(<AppleEvent>:I run perl scripts by BBEdit)
>
>__-2806__ is a "fragment container format unknow" error.

Yes, because it's not a shared library.

>For resume, the principal question is: how to build a Math64Lib format
>library with CodeWarrior?

Select "Shared Library" in the build options.

>Does specifics librarys are required to link?

Yes, plenty of them. Look in BuildRules.mk and ExtBuildRules.mk in the
source distribution for a list. You will also need to link with macPerl
itself for any nontrivial extensions.

>Does instruction @EXPORT = qw(test) in TestCLib.pm necessary?

Yes, if you want to call it as test() and not as TestCLib::test()

>And is it possible to put the Math64Lib and the .pm module in the same
>folder?

I don't think so. The idea is that any dynamically loaded components
(autoloaded subroutines and shared libraries) are loaded from auto.

>If not, why the lib:MacPPC:auto:... folder of Perl is an obligation to
>store?

The way I see it, the platform specific auto folders are useful to quickly sort
out what libraries you want.

Matthias

-----
Matthias Neeracher   <neeri@iis.ee.ethz.ch>   http://www.iis.ee.ethz.ch/~neeri
   "I'm set free to find a new illusion" -- Velvet Underground

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch