我使用 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/