c++ - 编译 C++ 源代码以获得最大的可移植性

标签 c++ compiler-construction mingw gnu portability

我使用 C++ 创建了一个独立的可执行文件,我希望它能被尽可能多的人使用。在编译器选项方面,我能做些什么来确保这一点?我将 MinGW 与链接器选项 -static-libgcc -static-libstdc++ 结合使用。我的可能用户将使用 Windows 7。

编辑:我已经尽可能让我的源代码具有可移植性。 This webpage提到了“最大可移植性”的论点 ANSI (-A)。使其与 ANSI 兼容有什么影响?

最佳答案

通过 g++,您可以使用很多警告标志。 -Wall 已经可以提供帮助,但还有很多其他的,例如:

-Werror -Wall -Wextra -pedantic -std=gnu++0x -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Winit-self -Wlogical-op -Wmissing-include-dirs -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=1 -Wundef -Wno-unused -Wunused-variable -Wno-variadic-macros -Wno-parentheses -Wno-unknown -pragmas -Wwrite-strings -Wswitch -fdiagnostics-show-option -Wnoexcept -Wold-style-cast -Wformat=2

它不会使您的代码与所有 C++ 编译器兼容,但是,一旦您尝试使用其他编译器,它将有助于减少必要的工作。

要查看所有这些警告标志,请查看 g++ 的手册页或信息页。

关于c++ - 编译 C++ 源代码以获得最大的可移植性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16755290/

相关文章:

c++ - 遵循 OpenCV 3.4.0 AKAZE 和 ORB 平面跟踪教程时找不到 Points() 函数

c++ - 使用 RcppArmadillo submat() 更新通过引用传递的 Rcpp::NumericMatrix

c++ - limits.h 中的条件编译语句

c++ - 模板和单独编译

c++ - 刷新MFC界面 VC++ 2010

java - 为什么不能在方法中采用多个可变参数参数?

c - 如何修复对 _imp__* 的 undefined reference ?

c - 在没有副作用的情况下对 bool 操作数进行短路

c++ - 如何在 C++ 中实现 vector 混合?

c++ - boost.Geometry 运算符