简体   繁体   English

使用Visual Studio中的System()从Windows中的源c ++文件编译c ++代码

[英]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.

相关问题 如何在 Visual Studio 代码中编译和运行 c++ 源文件 - How to compile and run a c++ source file in visual studio code Visual Studio的C ++编译源文件 - C++ Compile source file from Visual Studio 在 visual studio 的 1 个项目中编译单个 c++ 源文件 - compile single c++ source file in 1 project in visual studio 如何在Mac上的c ++中编译源代码,以确保在遵循ANSI / ISO的同时在Windows Visual Studio编译器中正确编译源代码 - How should I compile source code in c++ on a mac to ensure it will compile correctly in Windows Visual Studio Compiler while adhering to ANSI/ISO 如何在visual studio中编译c ++文件? - How to compile c++ file in visual studio? 编译源(.C)文件时出现错误在Windows 7中通过GnuWin32使用Microsoft Visual C / C ++编译器 - Get Error When Compile Source (.C) file Using Microsoft Visual C/C++ compiler via GnuWin32 in Windows 7 通过Visual Studio中的C#类编译C ++代码 - Compile C++ code via C# class in Visual Studio 如何将SFML源代码包含到我的Visual Studio 2017 C ++项目中并进行编译 - How to include SFML source code into my visual studio 2017 c++ project and compile 如何在Visual Studio C ++中编译开源框架,只有“makefile”而没有解决方案文件? - How to compile open source framework in Visual Studio C++, that has “makefile” only and no solution file? 如何在Visual Studio 2015中使用clang编译C ++ for Windows - How to compile C++ for Windows with clang in Visual Studio 2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM