26.09.2022 14:38 Bonita Montero kirjutas:
> Am 26.09.2022 um 12:36 schrieb Paavo Helde:
>>
>> I know the order of TU-s is not determined when initializing the
>> global statics. But what about static libraries? Are the global
>> statics in static libraries initialized in the order I list the
>> libraries on the linker command-line? If so, it seems the needed order
>> would be in general opposite to the order needed for symbol resolving
>> dependencies.
>
> As there are usually no dependencies on the other global
> objects outside the library that's actually not a problem.
Except when there is (a problem). You do not need a dependency on a
global object, just calling a function using the non-constructed global
object is enough.
For fun, here are snippets from the concrete library which suddenly
started to fail:
Library aws-crt-cpp:
source file Api.cpp, namespace level
Allocator *g_allocator = Aws::Crt::DefaultAllocator();
source file allocator.c:
void *aws_mem_acquire(struct aws_allocator *allocator, size_t size) {
AWS_FATAL_PRECONDITION(allocator != NULL); // <----- FAILS -----
// ...
}
header file StlAllocator.h
extern AWS_CRT_CPP_API Allocator *g_allocator;
template <typename T> class StlAllocator :
public std::allocator<T>
{
public:
StlAllocator() noexcept : Base()
{ m_allocator = g_allocator; }
// ...
Allocator *m_allocator;
};
Library aws-cpp-sdk-core:
Header file AWSString.h:
using String = std::basic_string< char, std::char_traits< char >,
Aws::Allocator< char > >;
Source file AWSConfigFileProfileConfigLoader.cpp, namespace level:
const Aws::String IDENTIFIER_ALLOWED_CHARACTERS =
R"(%+-./0123456789:@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)";