[英]How to compile c++ code with system() function (MSVC)?
i am trying to compile a c++ file with system() function using c++.我正在尝试使用 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());
}
I know I can do that in developer cmd, but the system() function opens regular cmd, so it cannot recognize the "cl" command.我知道我可以在开发人员 cmd 中执行此操作,但是 system() 函数会打开常规 cmd,因此它无法识别“cl”命令。
Please tell how to open developer cmd or how to setup the environtment to compile the code via c++.请告诉如何打开开发人员cmd或如何设置环境以通过c ++编译代码。
You can do this by adding the path of cl
to the environment variables:您可以通过将
cl
的路径添加到环境变量中来做到这一点:
This can be done like so:这可以像这样完成:
run
in search.run
来执行此操作。sysdm.cpl
sysdm.cpl
path
and click edit
path
并单击edit
new
and add the path of your cl
command.new
并添加cl
命令的路径。 In my case the cl.exe
file is incl.exe
文件在C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\bin\\Hostx64\\x64
It doesn't vary all that much but you must use the correct path in your machine.它变化不大,但您必须在机器中使用正确的路径。
cl
command from any place in your machine.cl
命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.