Search Unity

Question In-game player compiler error

Discussion in 'Scripting' started by Viroz_, Jan 30, 2023.

  1. Viroz_

    Viroz_

    Joined:
    Dec 30, 2022
    Posts:
    17
    Hi

    I am making a game about programming and I want to add code editor with g++ compiler which player can use.

    My variables:
    Code (CSharp):
    1.     private readonly string directoryPath = $"{Application.persistentDataPath}/tmp";
    2.     private readonly string outputFilePath = $"{Application.persistentDataPath}/tmp/pablo.exe";
    3.     private readonly string inputFilePath = $"{Application.persistentDataPath}/tmp/usercode.cpp";
    4.     private readonly string compilerPath = $"\"{Application.streamingAssetsPath}/g++.exe\" ";
    Code (CSharp):
    1. private void Compile()
    2.     {
    3.         CreateFile();
    4.         UnityEngine.Debug.Log(compilerPath + "-o \"" + outputFilePath + "\" " + "\"" + inputFilePath + "\"");
    5.         var process = new Process
    6.         {
    7.             StartInfo = new ProcessStartInfo
    8.             {
    9.                 FileName = compilerPath,
    10.                 Arguments = "-o \"" + outputFilePath + "\" " + "\"" + inputFilePath + "\"",
    11.                 RedirectStandardOutput = true,
    12.                 RedirectStandardError = true,
    13.                 UseShellExecute = false,
    14.                 CreateNoWindow = true
    15.             }
    16.         };
    17.         process.Start();
    18.         string output = process.StandardOutput.ReadToEnd();
    19.         string error = process.StandardError.ReadToEnd();
    20.  
    21.         process.WaitForExit();
    22.  
    23.         if (process.ExitCode == 0)
    24.         {
    25.             UnityEngine.Debug.Log("Compilation succeeded");
    26.         }
    27.         else
    28.         {
    29.             UnityEngine.Debug.LogError("Compilation failed: " + error);
    30.         }
    31.     }
    And I have compiler in my StreamingAssets folder, but when I try to run my code, it occures an error:
    Compilation failed: g++.exe: fatal error: cannot execute 'cc1plus': CreateProcess: No such file or directory
    compilation terminated.

    The command compiler is executing:
    "D:/.Coding/games/newHero/New Hero/Assets/StreamingAssets/g++.exe" -o "C:/Users/Viroz/AppData/LocalLow/TCG/New Hero/tmp/pablo.exe" "C:/Users/Viroz/AppData/LocalLow/TCG/New Hero/tmp/usercode.cpp"


    When I try it in terminal it also gives me the same error.

    Thanks in advance.
     
    SemiGodProgrammer likes this.