If you compile to WVM you can use DumpSave[]:
SetDirectory[NotebookDirectory[]] ;
F = Compile[{{x}}, x^2 + Sin[x^2]];
DumpSave["F.mx", F] ;
Clear[F];
<< F.mx ;
F[10.]
For C functions, Mathematica creates a library (dll or so) and then link it. The library is saved in a temporarily directory and removed when session ends. It is possible to copy created lib and use it latter. All relevant data needed to link the function:
SetDirectory[NotebookDirectory[]] ;
<< CompiledFunctionTools`;
F = Compile[{{x}},x^2+Sin[x^2],CompilationTarget->"C"];
F[[-1,1]] (* file location *)
F[[-1,2]] (* generic function name*)
F[[-1,3]] (* in arg *)
F[[-1,4]] (* out arg *)
Here is an example:
(* copy lib and get loading data *)
SaveFunc[name_,file_]:=Block[
{
data=Last[name]
},
CopyFile[
data[[1]],
StringJoin[file,".dll"] (* replace with .so on linux *)
];
{file,data[[2]],data[[3]],data[[4]]}
];
(* load lib *)
LoadFunc[savedata_]:=Block[
{ },
FindLibrary[Directory[]<>StringJoin["/",savedata[[1]]]];
LibraryFunctionLoad[
Directory[]<>StringJoin["/",savedata[[1]]],
savedata[[2]],
savedata[[3]],
savedata[[4]]
]
];
savedata = SaveFunc[F,"TEST"]
G = LoadFunc[savedata]
F[10.]
G[10.]
From my experience it is possible to use generated libs on other computers (of course you can't use .dll on linux or .so on windows).
The only issue may be hardware dependent compilation of the lib, but default compiler flags do not do it.
I.M.