I am new at using CCompilerDriver[]. I call the C compiler from W Mathematica using recent WM 11.3 update. It successfully identifies the Visual Studio 2017, But calling compiler returns errors.
Needs["CCompilerDriver`"]
CCompilers[]
hello = CreateExecutable["
#include <stdio.h>
int main(){
printf(\"hello world\\n\");
}
", "hello"]
Import["!" <> QuoteFile[hello], "Text"]
I copy the sample test code from the WM documentation CCompilerDriver/ref/CreateExecutable
The output shows to recognize VS2017 , but fails to compile due to files missing. Please help with how to tell WM to find the missing files.
Out[2]= {{"Name" -> "Visual Studio", "Compiler" ->
CCompilerDriverVisualStudioCompiler
VisualStudioCompiler,
"CompilerInstallation" -> "C:\Program Files (x86)\Microsoft Visual \ Studio\2017\Community", "CompilerName" -> Automatic}, {"Name" -> "Visual Studio", "Compiler" ->
CCompilerDriverVisualStudioCompiler
VisualStudioCompiler,
"CompilerInstallation" -> "C:\Program Files (x86)\Microsoft Visual \ Studio\2017\BuildTools", "CompilerName" -> Automatic}}During evaluation of In[1]:= CreateExecutable::cmperr: Compile error: C:\Users\user\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\Working-asus-8568-6984-1\hello.c(2): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
Out[3]= $Failed > > During evaluation of In[1]:= StringJoin::string: String expected at > position 2 in !<>QuoteFile[$Failed].
During evaluation of In[1]:= Import::chtype: First argument !<>QuoteFile[$Failed] is not a valid file, directory, or URL > specification. > > Out[4]= $Failed
Additional information about my machine
version 11.3.0 for Microsoft Windows64-bit March 7, 2o18 Release ID 11.3.0.0
I have installed both compilers, the Visual Studio IDE and the Visual Studio Built Tools
1 st UPDATE:::
I forgot to mention that I am also beginner to C++ . I compiled the code above in VS2017 IDE and returned errors. It looks the samples from the WM Documentation do not necessarily compile in the C++ compiler.
Have this said, I replaced the code with a sample code that showed to compile in VS2017 IDE. The result appears to have compiled in WM, but can not the Import line returned error. I can not associate this error to the compilation is related at all. Please , comment.
Needs["CCompilerDriver`"]
CCompilers[]
hello = CreateExecutable["
// Hello100.cpp : Defines the entry point for the console \
application.
//
#include " stdafx.h "
#include <iostream>
// i/o example
// stringstreams
#include <string>
#include <sstream>
using namespace std;
int main()
{
string mystr;
float price = 0;
int quantity = 0;
int next;
cout << " Enter price : ";
getline(cin, mystr);
stringstream(mystr) >> price;
cout << " Enter quantity : ";
getline(cin, mystr);
stringstream(mystr) >> quantity;
cout << " Total price : " << price * quantity << endl;
cin >> next;
return 0;
}
", "hellomyfirst"];
Import["!" <> QuoteFile[hellomyfirst], Text]
The output :
In[36]:= Import["!" <> QuoteFile[hellomyfirst], Text]
During evaluation of In[36]:= StringJoin::string: String expected at position 2 in !<>QuoteFile[hellomyfirst].
During evaluation of In[36]:= Import::chtype: First argument !<>QuoteFile[hellomyfirst] is not a valid file, directory, or URL specification.
Out[36]= $Failed
2 st UPDATE:::
Found the issue.. It is correct all the comments shared by contributors. Need the C++ SDK .. but must important is that in addition must have Windows 10 In my case, my laptop was using Windows 8.1.
Import
should be the path to the compiled executable. $\endgroup$