We deliver solutions for the AI eraâcombining symbolic computation, data-driven insights and deep technology expertise.
wsprep addtwo.tm -o addtwotm.cwill produce a C source file addtwotm.c from the template entries and other text in addtwo.tm. You would then compile the output file using the C compiler. If you use the make utility to build your program, you could add a rule similar to the following one to your makefile.
addtwotm.c : addtwo.tmBuilding WSTP programs What follows is a sample makefile needed to build the sample programs in the WSDK, including addtwo and factor. To build a sample program, in this case addtwo, evaluate the following command in the WSTPExamples directory. Using a Makefile
wsprep addtwo.tm -o addtwotm.c
# This makefile can be used to build all or some of the sample
# programs. To build all of them, use the command
# 'make all'. To build one, say addtwo, use the command
# 'make addtwo'.WSTPLINKDIR = /usr/local/Wolfram/Mathematica/11.2/SystemFiles/Links/WSTP/DeveloperKit
SYS = Linux # Set this value with the result of evaluating $SystemID
CADDSDIR = ${WSTPLINKDIR}/${SYS}/CompilerAdditionsINCDIR = ${CADDSDIR}
LIBDIR = ${CADDSDIR}EXTRALIBS = -lm -lpthread -lrt -lstdc++ -ldl -libuuid # Set these with appropriate libs for your system.
WSTPLIB = WSTP32i4 # Set this to WSTP64i4 if using a 64-bit systemWSPREP = ${CADDSDIR}/wsprep
all : addtwo bitops counter factor factor2 factor3 quotient reverse sumalist
addtwo : addtwotm.o addtwo.o
${CC} -I${INCDIR} addtwotm.o addtwo.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@bitops : bitopstm.o bitops.o
${CC} -I${INCDIR} bitopstm.o bitops.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@counter : countertm.o
${CC} -I${INCDIR} countertm.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@factor : factor.o
${CC} -I${INCDIR} factor.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@factor2 : factor2.o
${CC} -I${INCDIR} factor2.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@factor3 : factor3.o
${CC} -I${INCDIR} factor3.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@quotient : quotient.o
${CC} -I${INCDIR} quotient.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@reverse : reversetm.o
${CC} -I${INCDIR} reversetm.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@sumalist : sumalisttm.o sumalist.o
${CC} -I${INCDIR} sumalisttm.o sumalist.o -L${LIBDIR} -l${WSTPLIB} ${EXTRALIBS} -o $@.c.o :
${CC} -c -I${INCDIR} $<addtwotm.c : addtwo.tm
${WSPREP} $? -o $@bitopstm.c : bitops.tm
${WSPREP} $? -o $@countertm.c : counter.tm
${WSPREP} $? -o $@reversetm.c : reverse.tm
${WSPREP} $? -o $@sumalisttm.c : sumalist.tm
${WSPREP} $? -o $@
Use the following table to determine the extra libraries needed for linking WSTP programs on your system.
$SystemID EXTRALIBS "Linux" -lm -lpthread -lrt -lstdc++ -ldl -luuid "Linux-x86-64" -lm -lpthread -lrt -lstdc++ -ldl -luuid Using wscc wscc is a script that preprocesses and compiles your WSTP source files. It will preprocess WSTP templates in any file whose name ends with .tm, and then call cc on the resulting C source code. wscc will pass command-line options and other files directly to cc. Following is a command that would build the addtwo application using wscc.wscc addtwo.tm addtwo.c -o addtwoThe instructions in "Building WSTP Programs" describe how to build two WSTP programs using source code in the WSTPExamples directory. These two programs, addtwo and factor, are already built for you in the PrebuiltExamples folder. Before building them on your own, you should try to run the prebuilt examples to verify that the WSTP system additions are installed and working and to learn what to expect from these examples when they are properly built. There are two basic types of WSTP program, epitomized by the addtwo and factor programs. The first is an installable program. An installable program provides new functionality to the kernel by linking a C program to the kernel through a calling mechanism. In order to get this new functionality, the user of the Wolfram Language must run the Install[] function. With the addtwo example, you will be adding a new function called AddTwo[] that adds two numbers (provided as arguments). The kernel and installable programs have a special relationship that allows them to communicate only with one another. When an installable program is run, it requires that you provide some information in order for it to connect. The other type of program is a front end. Front ends do all of the work of creating and managing their own links. In addition to the factor example, the Wolfram System front end and the Wolfram Language kernel are also examples of the front end type. A front end does not require any extra information in order to run, but it will usually make a connection at some point during its execution. Running a Prebuilt Example from the Wolfram Language Kernel The first example program, addtwo, is a WSTP template program that is installed into the Wolfram Language. That is, this program runs in the background, providing, as a service to the Wolfram Language, one or more externally compiled functions. To the Wolfram Language user, these functions appear to be built in. The addtwo program uses a template file that defines the Wolfram Language function AddTwo[] as a call to the C function addtwo(). (The template mechanism is described in "WSTP and External Program Communication".) The source code for this program looks like this.
:Begin:Edit the path string and evaluate the following two cells: To see a list of the newly available functions, evaluate this cell: This displays the usage message for the AddTwo[] function as defined in the file addtwo.tm: See what happens if the sum of the two machine integers will not fit in a machine integer or if either argument is not a machine integer. (2^31-1 is the largest machine integer. If your compiler uses 2-byte integers, then 2^15-1 is the largest C int.) The addtwo program is not prepared for big integers: This does not match AddTwo[_Integer, _Integer]: Install[] called LinkOpen[] and then exchanged information with the external program to set up the definition for AddTwo[]. You really do not have to worry about these details, but if you are curious, evaluate the following: When you are finished using the external program, evaluate the following: Invoking the Wolfram Language Kernel from Within a Prebuilt Example The second example program, factor, is a Wolfram System front end in the sense that the Wolfram Language kernel runs in the background providing, as a service to factor, the computational services of the kernel—in this case the ability to factor an integer typed by the user. Launch the factor application by executing the following command.
:Function: addtwo
:Pattern: AddTwo[i_Integer, j_Integer]
:Arguments: { i, j }
:ArgumentTypes: { Integer, Integer }
:ReturnType: Integer
:End::Evaluate: AddTwo::usage = "AddTwo[x, y] gives the sum of two machine integers x and y."
int addtwo( int i, int j)
{
return i+j;
}int main(int argc; char* argv[])
{
return WSMain(argc, argv);
}
factor -linkmode launch -linkname 'math -wstp'After a moment, a prompt will appear requesting that you type an integer. Type an integer with fewer than 10 digits and press the Enter key. (The other factor examples relax the restriction on the size of integer you may type in.) The prime factors returned by the Wolfram Language are printed and factor closes its link with the Wolfram Language.
Integer to factor: 123456789Supported Link Protocols The C function WSOpenArgcArgv() and the Wolfram Language function LinkOpen[] are documented in "WSTP and External Program Communication". On Linux machines, the legal values for the LinkProtocol option are "TCPIP", "TCP", "SharedMemory", "Pipes", and "IntraProcess". A LinkProtocol is the mechanism used to transport data from one end of a connection to the other. "SharedMemory" is the default protocol for all LinkMode->Launch links. "SharedMemory" is the default protocol for all LinkMode->Listen and LinkMode->Connect links. Note that link names are unsigned 16-bit integers for the "TCPIP" and "TCP" protocols. Even though "TCPIP" link names are integers, they are still given as strings (of digits) to WSOpenArgcArgv() and LinkOpen[].
3 ^ 2
3607 ^ 1
3803 ^ 1
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4