# ExportString and CreateExecutable

**URL:** <https://community.wolfram.com/t/exportstring-and-createexecutable/6575>\
**Category:** Questions\
**Tags:** compilation\
**Created:** [August 31, 2015, 4:02pm UTC](https://community.wolfram.com/t/exportstring-and-createexecutable/6575 "2015-08-31T16:02:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcolletti](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/bcolletti/32/12824_2.png) [@bcolletti](https://community.wolfram.com/u/bcolletti)\
**Post date:** [August 31, 2015, 4:02pm UTC](https://community.wolfram.com/t/exportstring-and-createexecutable/6575/1 "2015-08-31T16:02:17Z")

</div>

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 >>

```

---

<div class="post-metadata">

**Author:** ![bcolletti](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/bcolletti/32/12824_2.png) [@bcolletti](https://community.wolfram.com/u/bcolletti)\
**Post date:** [September 1, 2015, 2:04pm UTC](https://community.wolfram.com/t/exportstring-and-createexecutable/6575/2 "2015-09-01T14:04:37Z")

</div>

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](https://msdn.microsoft.com/en-us/library/aad7fash.aspx)

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

> **[Fatal Error C1083](https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1083?view=msvc-170&redirectedfrom=MSDN)**
>
> Learn more about: Fatal Error C1083

Any ideas on how to avoid this error?

---

<div class="post-metadata">

**Author:** ![iliang](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/iliang/32/11263_2.png) [@iliang](https://community.wolfram.com/u/iliang)\
**Post date:** [September 1, 2015, 5:48pm UTC](https://community.wolfram.com/t/exportstring-and-createexecutable/6575/3 "2015-09-01T17:48:54Z")

</div>

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:

> **[C Code Generation User Guide—Wolfram Documentation](https://reference.wolfram.com/language/CCodeGenerator/tutorial/Overview.html)**
>
> Code generation from the Wolfram Language involves converting programs written in the Wolfram Language into other languages and then supporting them so that they can be executed. The Wolfram System compiler provides a system for code generation into...

---

<div class="post-metadata">

**Author:** ![melmcclan](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@melmcclan](https://community.wolfram.com/u/melmcclan)\
**Post date:** [September 1, 2015, 6:19pm UTC](https://community.wolfram.com/t/exportstring-and-createexecutable/6575/4 "2015-09-01T18:19:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bcolletti](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/bcolletti/32/12824_2.png) [@bcolletti](https://community.wolfram.com/u/bcolletti)\
**Post date:** [September 2, 2015, 7:31pm UTC](https://community.wolfram.com/t/exportstring-and-createexecutable/6575/5 "2015-09-02T19:31:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![iliang](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/iliang/32/11263_2.png) [@iliang](https://community.wolfram.com/u/iliang)\
**Post date:** [September 7, 2015, 4:53pm UTC](https://community.wolfram.com/t/exportstring-and-createexecutable/6575/6 "2015-09-07T16:53:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bcolletti](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/bcolletti/32/12824_2.png) [@bcolletti](https://community.wolfram.com/u/bcolletti)\
**Post date:** [September 11, 2015, 6:31am UTC](https://community.wolfram.com/t/exportstring-and-createexecutable/6575/7 "2015-09-11T06:31:51Z")

</div>

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