Changeset 40212 in project


Ignore:
Timestamp:
06/22/21 10:14:31 (6 weeks ago)
Author:
svnwiki
Message:

Anonymous wiki edit for IP [184.19.112.66]: Add examples for compiling a module and linking it into a program, and show how to do it with the csm egg.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/man/5/Modules

    r36941 r40212  
    340340must be available separately.
    341341
     342=== Example of compiling modules and linking them into an executable
     343
     344Here is a test module, in the file mymod.scm:
     345
     346<enscript highlight=scheme>
     347(module mymod (hello)
     348  (import scheme)
     349  (define (hello)
     350    (display "Hello, World, I'm in mymod!")
     351    (newline)))
     352</enscript>
     353
     354Here is the main module, in the file trymod.scm:
     355
     356<enscript highlight=scheme>
     357(module trymod ()
     358  (import scheme)
     359  (import mymod)
     360  (display "I'm in trymod!")
     361  (newline)
     362  (hello)
     363  (display "Now I'm back in trymod!")
     364  (newline))
     365</enscript>
     366
     367To compile mymod.scm and trymod.scm and link them into the executable trymod, issue the following commands:
     368
     369  csc -c -J mymod.scm -unit mymod -o mymod.o
     370  csc -o trymod mymod.o -uses mymod trymod.scm
     371
     372This creates an executable that is dynamically linked against libchicken.so.
     373
     374To create an executable that is statically linked, issue the following commands:
     375
     376  csc -c -static -J mymod.scm -unit mymod -o mymod.o
     377  csc -o trymod -static mymod.o -uses mymod trymod.scm
     378
     379If you later add another module you'd need to compile it similar to how mymod.scm is
     380compiled and add a "modulename.o -uses modulename" to the csc command that compiles trymod.scm.
     381
     382It is possible to use the csm program installed by the [[/egg/csm|csm egg]] to do this automatically.  To produce a dynamically linked program you would do:
     383
     384  csm -program trymod
     385
     386To produce a statically linked program you would do:
     387
     388  csm -static -program trymod
    342389
    343390=== Functors
Note: See TracChangeset for help on using the changeset viewer.