Method 1: Enable messages for new symbols and load MX file
The following code will load MX file and show a
General::newsym message for each newly created symbol.
On[General::newsym]; (* enable message for each new symbol *)
Off[General::stop]; (* prevent stop after 3 messages *)
Get["file.mx"]; (* load MX file *)
Advantage: This method shows new symbols in all contexts, not only in
This is useful if you don't know the context of the variables stored in the MX file.
Disadvantage: Only newly created symbols will be reported.
If a symbol is already defined in your current Mathematica session
and MX file updates/redefines this symbol, then no message will be shown.
Method 2: Load MX file and save new symbols into a List
If you want to save the names of newly created symbols into a list,
you can use the
The following function (based on this post by @Leonid Shifrin)
will load an MX file and return a list of newly created symbols including their contexts:
newSymbols[mxfile_] := Module[
This method has the same advantages and disadvantages as Method 1.
Method 3: Use auxiliary kernel to inspect the contents of MX file
This method will be helpful if you want to know which symbols are defined by MX symbols,
but don't want to load MX file into your current session.
You can start a fresh auxiliary kernel, load MX file there, save a list of newly created symbols,
and quit auxiliary kernel.
This algorithm can also be automated:
(* newKernelEvaluate starts a fresh auxiliary kernel, evaluates expr, *)
(* quits auxiliary kernel, and returns the result of evaluation. *)
Attributes[newKernelEvaluate] = HoldAll;
newKernelEvaluate[expr_] := Module[
link = LinkLaunch[First@$CommandLine <> " -mathlink -noprompt"];
result = LinkRead@link;
Replace[result, ReturnPacket@x_ :> x]
getSymbolsDefinedInMX[mxfile_] := Module[
You can now run
getSymbolsDefinedInMX["file.mx"] to get a list of symbols defined in this MX, without actually loading any symbols in the current session.
This method will detect almost all symbols defined by MX. Only redefinitions of built-in symbols will not be detected.
If you spot
System`Private`ConvertersPrivateDumpSymbol among the symbols which are created by your MX file, then this MX file was created using
Export["file.mx", someExpression] (see the answer of R.M. above). In this case you can just use
someVariable = Import["file.mx"].