我们在批处理模式下使用 G++ 时遇到错误
we got errors using g++ in batch mode
编译
#include <stdio.h>
main()
{ int rtn=0;
printf("nmain hello world",rtn);
fin:
return(rtn);
}
安装 DEV-CPP 后交互式 从 https://sourceforge.net/projects/orwelldevcpp/下载 使用嵌入式 IDE 产生"成功安装"; 尝试与 WINDOWS 7 专业版 64 位操作系统批处理脚本"相同">
set p1=-I"C:Program Files (x86)Dev-CppMinGW64include"
set p2=-I"C:Program Files (x86)Dev-CppMinGW64x86_64-w64-mingw32include"
set p3=-I"C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2include"
set p4=-I"C:Program Files (x86)Dev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec++"
set p5=-L"C:Program Files (x86)Dev-CppMinGW64lib"
set p6=-L"C:Program Files (x86)Dev-CppMinGW64x86_64-w64-mingw32lib"
g++ -g cc_hello_world.cpp -o cc_hello_world -lm %p1% %p2% %p3% %p4% %p5% %p6%
产生无休止的错误报告,从
In file included from C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\_cygwin.h:14,
from C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\_mingw.h:17,
from C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\crtdefs.h:10,
from C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\stdio.h:9,
from cc_hello_world.cpp:1:
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\stddef.h:18:
syntax error before `extern'
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\stddef.h:20:
warning: ANSI C++ forbids declaration `errno_t' with no type
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\stddef.h:20:
warning: `__cdecl__' attribute directive ignored
...
我们只引用前七行。 虽然信天翁 http://www.cplusplus.com/articles/36vU7k9E/认为我们会很感激 一些提示我们在哪里继续研究以解决此类问题。
你的代码有很多问题,无论是 Batch 还是 C++。如果您尝试将某些内容打印到控制台,并且出于某种原因想要使用 Batch 脚本,请使用system()
命令(我建议将其抽象为递归可变参数函数(。
#include <cstdio>
#include <string>
#include <utility>
#include <fstream>
void make_batch() { return; }
template<typename ComTy, typename... OtherTy>
void make_batch(std::ofstream& bat_file, ComTy command, OtherTy... other_commands)
{
bat_file << command;
make_batch(bat_file, std::forward<OtherTy>(other_commands)...);
}
template <typename... ComTy>
void batch(ComTy... commands)
{
std::ofstream bat_file_write("temp.bat");
if (bat_file_write.is_open())
{
// Make the batch script
make_batch(bat_file_write, std::forward<OtherTy>(commands)...);
bat_file_write.close();
system("temp.bat"); // Execute the batch script
}
}
int main()
{
batch(
"rtn=0",
"echo.",
"echo main hello world %rtn%",
"fin:",
"exit"
);
}
但是,如果您的意思是只想从命令提示符调用编译器,则必须编写正确的C++代码。
#include <cstdio>
int main()
{
int rtn = 0;
printf("nmain hello world %i", rtn);
return rtn;
}
然后像往常一样编译该代码。
现在我可能没有完全理解你的问题。如果是这种情况,请告诉我,我会尽力澄清。
相关文章:
- 编译包含字符串的代码时遇到问题
- 遇到新行时,有没有办法停止istream_iterator
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 在 for 循环中查找问题时遇到困难
- 创建结构的数组时遇到分段错误
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 为什么我遇到分段错误?
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- 为什么我在尝试模板时遇到视觉工作室C++错误
- 如何从文本文件中读取数值,直到遇到字符类型?
- 从其他类访问类时遇到问题
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 打印问题.我在数组中打印值时遇到一些问题
- 使用静态成员声明类时遇到问题
- 创建 Spdlog 异步文件记录器时遇到困难
- C++ 填充数组时遇到问题
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字
- 查找奇数平方和时遇到麻烦