MSVS 2010 和 C++ 标准的构建问题

2021-12-31 00:00:00 standards compiler-errors visual-c++ c++

我正在尝试使用 msvs 2010 构建在以下 git 中找到的项目:

https://github.com/Joonhwan/exprtk

问题是当我注释掉 exprtk.hpp 文件中的第 48 行 '#define exprtk_lean_and_mean' 时,我收到以下编译器错误:

错误 1 ??错误 C1128:节数超出目标文件格式限制:使用/bigobj 编译

谷歌搜索错误,似乎表明编译的翻译单元已编译为大于任意限制的内容,并且在命令行中添加bigobj"应该可以解决问题(确实如此).使用 gcc (4.3) 编译代码,工作正常.

我的问题是:

  1. c++ 是否对翻译单元中可以包含的类型数量设置了限制?

  2. 这个项目的代码布局方式是不是不好?(在谷歌搜索时我注意到很多 boost 库都有同样的问题,例如:Boost.Sprit)

解决方案

c++ 是否对翻译单元中的类型数量有限制?

请注意,对于特定实现,此类参数的最大值是开放的.该标准仅强制实施必须支持的最低要求.实现将记录它支持的最大值,在这种情况下,MSVC 实现就是这样做的.

这些是在 C++ 标准的一个特殊部分中定义的.

附件 B - 实施数量

<块引用>

  1. 因为计算机是有限的,所以C++的实现必然是有限的在程序的大小上,他们可以成功处理.每实施应记录那些已知限制.这文档可能会引用固定限制它们存在的地方,说如何计算作为函数的可变限制可用资源,或者说是固定的限制不存在或未知.

  2. 限制可能会限制数量,包括以下描述的数量或其他.括号内的数字如下每个数量被推荐为该数量的最低限度.但是,这些数量只是指导方针并且不确定合规性.
    ――复合语句的嵌套级别,迭代控制结构,和选择控制结构 [256].
    ―条件嵌套级别包含 [256].
    ― 指针、数组和函数声明符(在任何组合)修改算术,结构、联合或不完整类型在声明中 [256].
    ― 嵌套括号表达式的级别在一个完整的表达式中 [256].
    ――内部字符数标识符或宏名称 [1 024].
    ――外部字符数标识符 [1 024].
    ― 外部一个翻译单元中的标识符[65 536].
    ― 带块的标识符在一个块中声明的范围 [1 024].
    ――同时宏标识符在一个翻译单元中定义 [65536].
    ― 一个函数中的参数定义 [256].
    ― 参数合二为一函数调用 [256].**
    ― 参数一个宏定义 [256].
    ――一次宏调用中的参数[256].
    ― 合乎逻辑的字符源代码行 [65 536].
    ― 中的字符字符串文字或宽字符串文字(连接后)[65 536].
    ― 物体的大小 [262144].
    ― #include 的嵌套级别文件 [256].
    ― 案例标签switch 语句(不包括那些用于任何嵌套的 switch 语句)[16384].
    ― 单个数据成员类、结构或联合 [16 384].
    ―单个枚举常量枚举 [4 096].
    ― 级别嵌套类、结构或联合单一定义结构声明列表 [256].
    ――由 atexit()[32] 注册的函数.
    ― 直接和间接基类 [16384].
    ― 的直接基类单班[1024].
    ― 成员在单个类中声明 [4 096].
    ―最终覆盖虚函数一个类,可访问或不可访问 [16 384].
    ――一个的直接和间接虚基类 [1 024].
    ― a 的静态成员类 [1 024].
    ― 好友声明在一个班级中 [4 096].
    ― 访问控制类中的声明 [4 096].
    ――构造函数中的成员初始值设定项定义 [6 144].
    ― 范围一个标识符的资格[256].
    ― 嵌套外部规格 [1 024].
    ― 模板模板声明中的参数 [1024].
    ― 递归嵌套模板实例化 [17].
    ― 每个处理程序尝试块 [256].
    ― 投掷单一功能的规格声明[256].

I'm trying to build, using msvs 2010 the project found at the following git:

https://github.com/Joonhwan/exprtk

The problem is when I comment out the line 48 '#define exprtk_lean_and_mean' in exprtk.hpp file, I get the following compiler error:

Error   1   error C1128: number of sections exceeded object file format limit : compile with /bigobj

Googling the error, seems to indicate the the compiled translation unit has compiled to something larger than an arbitariy limit, and adding 'bigobj' to the command line should fix the problem (which it does). Compiling the code with gcc (4.3), works without a glitch.

My questions are:

  1. Does c++ place a limit on the number of types that can be had in a translation unit?

  2. Is the way the code is laid out in this project bad practice? (when googling I noticed a lot of boost libraries have the same problem eg: Boost.Sprit)

解决方案

Does c++ place a limit on the number of types that can be had in a translation unit?

Note that the maximum values of such parameters are left open for particular implementations. The standard only enforces minimum requirements that must be supported by an implementation. An implementation will document the maximum values it supports and in this case MSVC implementation does so.

These are defined in a special section of the C++ standard.

Annex B - Implementation quantities

  1. Because computers are finite, C + + implementations are inevitably limited in the size of the programs they can successfully process. Every implementation shall document those limitations where known. This documentation may cite fixed limits where they exist, say how to compute variable limits as a function of available resources, or say that fixed limits do not exist or are unknown.

  2. The limits may constrain quantities that include those described below or others. The bracketed number following each quantity is recommended as the minimum for that quantity. However, these quantities are only guidelines and do not determine compliance.
    ― Nesting levels of compound statements, iteration control structures, and selection control structures [256].
    ― Nesting levels of conditional inclusion [256].
    ― Pointer, array, and function declarators (in any combination) modifying an arithmetic, structure, union, or incomplete type in a declaration [256].
    ― Nesting levels of parenthesized expressions within a full expression [256].
    ― Number of characters in an internal identifier or macro name [1 024].
    ― Number of characters in an external identifier [1 024].
    ― External identifiers in one translation unit [65 536].
    ― Identifiers with block scope declared in one block [1 024].
    ― Macro identifiers simultaneously defined in one translation unit [65 536].
    ― Parameters in one function definition [256].
    ― Arguments in one function call [256].**
    ― Parameters in one macro definition [256].
    ― Arguments in one macro invocation [256].
    ― Characters in one logical source line [65 536].
    ― Characters in a character string literal or wide string literal (after concatenation) [65 536].
    ― Size of an object [262 144].
    ― Nesting levels for #include files [256].
    ― Case labels for a switch statement (excluding those for any nested switch statements) [16 384].
    ― Data members in a single class, structure, or union [16 384].
    ― Enumeration constants in a single enumeration [4 096].
    ― Levels of nested class, structure, or union definitions in a single struct-declaration-list [256].
    ― Functions registered by atexit()[32].
    ― Direct and indirect base classes [16 384].
    ― Direct base classes for a single class [1024].
    ― Members declared in a single class [4 096].
    ― Final overriding virtual functions in a class, accessible or not [16 384].
    ― Direct and indirect virtual bases of a class [1 024].
    ― Static members of a class [1 024].
    ― Friend declarations in a class [4 096].
    ― Access control declarations in a class [4 096].
    ― Member initializers in a constructor definition [6 144].
    ― Scope qualifications of one identifier [256].
    ― Nested external specifications [1 024].
    ― Template arguments in a template declaration [1 024].
    ― Recursively nested template instantiations [17].
    ― Handlers per try block [256].
    ― Throw specifications on a single function declaration [256].

相关文章