ExportString and CreateExecutable

Re v10.2 under Windows 8.1.

What causes the two error messages below? One says to convert code to DOS format – but doesn’t Mathematica pump out C99-standard code? Is this fix as simple as specifying some option to CreateExecutable? Notice that the ExportString output is atch’d (there’s a renegade leading quote).

Maybe there’s a known problem with the installed C compiler. Maybe the first message causes the other. No doubt user-error is the culprit but I don’t know.

Thanks.

Bruce


The code is:

Needs@"CCompilerDriver`";
CCompilers[]
g=Compile[{x},x^2];
cCode=ExportString[g,"C"]; (* code is atch'd as CCode.txt *)
CreateExecutable[cCode,"mine"]

CCompilers[] above returns:

{{"Name" -> "Visual Studio", 
  "Compiler" -> 
   CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler, 
  "CompilerInstallation" -> 
   "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0", 
  "CompilerName" -> Automatic}}

The error messages are

CreateExecutable::cmperr: Compile error: C:\Users\Bruce\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Wind\[Ellipsis] format detected: please convert the source file to either DOS or UNIX format >>

CreateExecutable::cmperr: Compile error: C:\Users\Bruce\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Wind\[Ellipsis]  file: 'm-dde41816-6467-4e82-b364-babb0f35cfd0.h': No such file or directory >>

The first error message “…convert to DOS …” is tied to MS error C4335 that appeared when I re-ran the code –
see Compiler Warning (level 1) C4335 | Microsoft Learn

The string ExportString[g,“C”] had embedded ‘\r’ Mac characters (I’m running Windows) that were struck by:

sourceCode = 
  Characters@StringReplace[ExportString[g, "C"], "\r" -> ""] // StringJoin;

Now when I run:

CreateExecutable[sourceCode, "xyz", "TargetDirectory" -> "c://temp"]

only the second error message remains – it’s tied to error C1083; see

Any ideas on how to avoid this error?

The Mac line endings shouldn’t be there, it sounds like a bug.

The second error message is expected, because there is no header (.h) file generated. Also, to make a standalone executable you would need to supply an appropriate main() function and link to appropriate runtime libraries. See the following tutorial for a couple of examples:

It must be Apple here’s Dos

Needs["CCompilerDriver"]
CCompilers[]
g=Compile[{x},x^2];
cCode=ExportString [g,"C"];    
CreateExecutable[cCode,"mine"]

This gives the same output without the errors in dos

Thank you for the reply, Melvin. I’ve entered your code but it seems to be the same as before – the same errors arise.

But it worked for you and so that suggests that your setup differs from mine. What is your OS and C Compiler?

There is no OS or C compiler where this code fragment by itself could be compiled into an executable, for the reasons mentioned above.

Most likely Melvin’s post indicates he didn’t see the first (DOS format) error.

For those who are interested, I’ve started the new thread titled CreateExecutable that is rooted in the one here.