GCC在一台计算机上编译而在另一台计算机上编译时给出错误
gcc gives an error when compiling on one computer but not another
我在两台Ubuntu电脑上编译了一个程序。两者都运行14.04,可能是gcc的相同版本。但是当我在一台计算机上编译它时,我得到了错误
warning: format ‘%i’ expects argument of type ‘int’, but argument 4
has type ‘std::vector<colorgrad>::size_type {aka long unsigned int}’ [-Wformat=]
我认为违规代码是
for (vector<colorgrad>::size_type i = 0; i < grad.size(); ++i) {
fprintf(svgOut, "%s%i%s%f%srgb(%i, %i, %i)%sn", "<stop id="stop", i,"" offset="",grad.at(i).perc ,"" style="stop-color: ",grad.at(i).r, grad.at(i).g, grad.at(i).b, ";stop-opacity:1;" />" );
}
当我用"%lu"替换第一个"% I"时,错误就消失了,但是当我在另一台计算机上编译该代码时,gcc给出相反的错误,并且只会编译"% I"。
我如何让这段代码在两台计算机上编译,而不必每次切换计算机时都切换出"% I"??
如注释vector::size_t
所述,取决于平台,可能是32位或64位和格式%zu
管理。
或者,你可以这样写:
(我使用c++ 11, for-range,原始字符串(不必转义"
),但它也可以在c++ 03中完成)
std::ofstream oss; // initialize it with correct value
std::size_t i = 0;
for (const auto& color : grad) {
oss << R"(<stop id="stop)" << i << R"(" offset=")" << color.perc
<< R"(" style="stop-color: rgb()"
<< color.r << ", " << color.g << ", "<< color.b
<< R"();stop-opacity:1;" />)" "n"; // you may replace "n" by std::endl
++i;
}
相关文章:
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- 在另一台 PC 上执行程序时加载 SDL2 共享库时出错
- 另一台电脑上的Visual Studio C++项目无法生成
- Homebrew OS X OpenCV - 在另一台Mac上运行时寻找dylib
- 当我在支持 avx2 的机器上编译并在另一台仅支持 avx 的机器上运行二进制文件时会发生什么?
- 如何在另一台未安装 Visual Studio 的计算机中使用由 Visual Studio 生成的 dll
- 在另一台计算机中运行 GTKMM 代码时未定义的符号
- 为什么我不能在另一台电脑上运行自己的dll(msvcrt.dll被错过)
- 仅在一台计算机上出现"0xc000007b Application Unable to Start Correctly"错误
- 将Visual Studio C 构建的中间文件移至另一台计算机
- 为什么我的Glreadpixels程序在另一台计算机中不起作用
- Qt OpenGL帧缓冲在一台PC上创建,但在另一台PC上失败
- 为什么程序在一台计算机上而不是在另一台计算机上留下循环
- 如何在Linux / Windows操作系统上使用文件*.cpp一步编译下面的代码
- Wxwidgets 在另一台计算机上运行二进制文件时出现问题
- 程序在一台机器上编译,但不在另一台机器上编译
- 相同的android cmake git项目在一台Ubuntu机器上编译良好,但在另一台Ubuntu计算机上编译不好,即
- GCC在一台计算机上编译而在另一台计算机上编译时给出错误
- 编译后的python库可以在一台计算机上运行,但不能在另一台计算机上运行
- 在另一台计算机上启动使用MinGW编译的Windows应用程序时发生库链接错误