The bind
function allows you to build a stand alone
executable on Linux. The syntax for its use is
bind(output,mainexe,startcommand,varargin)
where output
is the name of the output binary,
mainexe
is the location of the FreeMat intepreter to be
used (e.g., '/usr/local/bin/FreeMat'
). The next argument
is the start command, i.e., the command to execute once the
interpreter is started. Generally speaking, it should be
-f main
where main
is the name of the routine to start
up. The last argument is the list of
M-files to bind into the executable as p-code. Note that
the resulting binary executable will pass arguments to your main
function automatically, see the example for example. Bound
executables can use graphics, MPI, and any other FreeMat
capabilities.
Here is the ubiquitous "hello world" example done FreeMat style. Note that this example will only work under Linux at the moment. Support for standalone executables on Mac OS and Windows is scheduled for a later version of FreeMat.
hello.m function hello(x) printf(' Hello %s\n',x);
Here is the hello
function from within FreeMat
--> hello('world!') Hello world!
Now we bind it into an executable.
--> bind('hello_bind','../../build/src/x11/FreeMat','-f hello','hello'); Reading main executable ../../build/src/x11/FreeMat Copying interpreter to output file hello_bind Pcoding support routine hello Translating hello to P-Code Copying Pcode for hello into output bundle... Writing closing tag information... Bundle successfully created.
We have to make the output executable and run it.
--> system('chmod +x hello_bind'); --> system('./hello_bind world!') ans = <cell array> - size: [0 1] []