【发布时间】:2020-03-27 15:02:17
【问题描述】:
我正在尝试使用 c++ 编译带有 system() 函数的 c++ 文件。
void CodeGenerator::GenerateExe(ProgramNode* parsed_tree, std::string folder_path, std::string file_name)
{
std::string cpp_name = folder_path + file_name + ".cpp";
GenerateCppFile(parsed_tree, cpp_name);
std::string command;
command += "cl ";
command += cpp_name + " /OUT ";
command += folder_path;
system(command.c_str());
}
我知道我可以在开发人员 cmd 中执行此操作,但 system() 函数会打开常规 cmd,因此它无法识别“cl”命令。
请告诉如何打开开发者 cmd 或如何设置环境以通过 c++ 编译代码。
【问题讨论】:
-
cl.exe 必须在路径中才能运行。您还需要使用 vcvarsall.bat 设置环境(这是您在 Visual Studio 中打开开发人员命令提示符时执行的那个)
-
你首先需要知道 CL.exe 的路径,而不是使用 system 而是 CreateProcessW
标签: c++ windows visual-studio