E2177 Redeclaration of #pragma package with different arguments (C++)
Go Up to Compiler Errors And Warnings (C++) Index
Error E2177 is typically encountered when #pragma package(smart_init)
is used in a header file (this is not recommended), and then another #pragma package(smart_init)
is used in a source module that #include
s the header file. The different arguments that the error refers to are the filenames of the header and the source file. The compiler cannot determine which unit name to use.
More Details
The #pragma package(smart_init)
tells the compiler to tell the linker that this
is a unit. The compiler does that by generating two comment records: one
that specifies the unit's name. and one that specifies the unit's flags. You can see
these by running tdump.exe on the object file.
When handling "unit" object files, the linker performs additional analysis to determine the order
in which the units' global objects should be initialized. To compute the order, the linker looks at references to other "unit" object
files. Note that if there are circular dependencies between objects, the order between them is undefined. Also note that "unit" semantics can alter the order in which global object constructors and #pragma startup/exit
routines are invoked. If your code does not refer to symbols declared in Delphi units (such as VCL or FMX) and does not have dependencies on the order of global object construction (most C++ code does not), then you probably do not need "unit" semantics, and you can remove the #pragma package(..)
generated by the File > New > Unit - C++Builder