Changeset 40213 in project


Ignore:
Timestamp:
06/22/21 16:54:07 (6 weeks ago)
Author:
svnwiki
Message:

Anonymous wiki edit for IP [184.13.240.130]: Explain why the compiling has to be done like it is.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/man/5/Modules

    r40212 r40213  
    365365</enscript>
    366366
     367You can compile mymod.scm into a shared object and compile trymod.scm into an executable  trymod that uses that shared object like this:
     368
     369  csc -s -J mymod.scm
     370  csc trymod.scm
     371
     372You can execute trymod and it will load the shared object mymod.so.  When loading a shared
     373object, the CHICKEN runtime uses the libld API to obtain the entry point ("C_toplevel") to invoke top-level initialization code of the module (which also setups up global bindings, etc.).  However, if you move the trymod executable to another directory, it won't be able to find mymod.so to load it.  If you want include the object into the executable directly, it needs to have a unique entry point name, separate from any other entry point of other linked modules. 
     374
     375To give the module a name, we pass the "-unit modulename" argument to csc, and the name of the module is added to the entry point, so the entry point for mymod would become "C_mymod_toplevel".  Then the "-uses modulename" argument is passed to csc while compiling and linking trymod so it knows to use that entry point.
     376
    367377To compile mymod.scm and trymod.scm and link them into the executable trymod, issue the following commands:
    368378
     
    370380  csc -o trymod mymod.o -uses mymod trymod.scm
    371381
    372 This creates an executable that is dynamically linked against libchicken.so.
     382This creates an executable that is dynamically linked against libchicken.so, but which includes the mymod.o object file directly.
    373383
    374384To create an executable that is statically linked, issue the following commands:
Note: See TracChangeset for help on using the changeset viewer.