OpenersNotesSection(Spacer1)Details

The MathLink environment object stores the global state of MathLink during the execution of a program.

A program can install custom memory allocators using the environment parameters object p.

An appropriate call to MLInitialize() is generated automatically when an external program is created from MathLink templates.

Any external program that uses the MathLink library must call MLInitialize() before calling any other link-related MathLink library functions.

The MathLink environment functions as a factory to create link objects.

MLInitialize() is declared in the MathLink header file (RefLink[mathlink.h, paclet:ref/file/mathlink.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include "mathlink.h"

int main(int argc, char **argv)
{
	MLENV ep;
	MLINK lp;
	int error;

	ep = MLInitialize((MLEnvironmentParameter)0);
	if(ep == (MLENV)0)
		{ /* unable to initialize environment */ }

	lp = MLOpenArgcArgv(ep, argc, argv, &error);
	if(lp == (MLINK)0 || error != MLEOK)
		{ /* unable to create link */ }

	/* ... */

	MLClose(lp);
	MLDeinitialize(ep);
	return 0;
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLNewParameters(), paclet:ref/c/MLNewParameters])  ▪  (NonWLLink[MLSetAllocParameter(), paclet:ref/c/MLSetAllocParameter])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Running the Wolfram System from within an External Program, paclet:tutorial/RunningTheWolframSystemFromWithinAnExternalProgram])}})}})