[英]Compile c++ code from source c++ file in windows using System() in Visual Studio
When I use Developer Command Prompt for VS2012 and type 当我将开发人员命令提示符用于VS2012并键入
cl myProgram.cpp
It compiles successfully , However, now I want to compile that same file from within my source code in mySourceCode.cpp 编译成功 ,但是,现在我想从mySourceCode.cpp的源代码中编译相同的文件
using 使用
system("cl myProgram.c");
When I try I get the following error 当我尝试时出现以下错误
fatal error c1034: proccess.h: no include path set 严重错误c1034:proccess.h:没有包含路径集
I was wondering if there was a way to fix this from within the source code without having to change any environment variables? 我想知道是否有一种方法可以从源代码中解决此问题而不必更改任何环境变量?
My Source code would look something like this: mySourceCode.cpp 我的源代码如下所示: mySourceCode.cpp
#include <iostream>
#include ...
int main()
{
//set up code
...
system("cl myProgram.c");
}
The code I want to compile: myProgram.cpp 我要编译的代码: myProgram.cpp
#include <proccess.h>
#include <windows.h>
#include <stdio.h>
int main()
{
//set up code
...
Sleep(10000);
}
When I use Developer Command Prompt for VS2012...It compiles successfully
当我为VS2012使用开发人员命令提示符时...成功编译
This should be a hint for you. 这应该是对您的提示。 Look what "Command Prompt for VS2012" link is -
%comspec% /k ""C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\vcvarsall.bat"" amd64
ie it launches vcvarsall.bat
file. 看什么是“ VS2012的命令提示符”链接-
%comspec% /k ""C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\vcvarsall.bat"" amd64
即启动vcvarsall.bat
文件。 Now look what that .bat
is doing - it uses parameter(s) and other .bat
files to set bunch of environment variables needed to successfully perform compilation, such as include path, library path and others. 现在看一下
.bat
在做什么-它使用参数和其他.bat
文件来设置成功执行编译所需的一堆环境变量,例如include路径,库路径等。
When you call system
most of those environment variables are not set in the process created by system()
call. 当您调用
system
大多数这些环境变量未在system()
调用创建的过程中设置。 If you want to perform compilation from your program you have many different ways to it. 如果要从程序执行编译,则有许多不同的处理方法。 For example, create a
.bat
file that you will launch, or use CreateProcess function to create a process with appropriate environment 例如,创建一个将启动的
.bat
文件,或使用CreateProcess函数在适当的环境中创建一个进程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.