Paavo Helde
unread,Nov 8, 2022, 6:35:32 AM11/8/22You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I have got a problem with a third-party library, which I am trying to
compile and use as a bunch of static Linux .a libraries. Suspecting the
problem would go away if I switched over to dynamic libraries instead,
but I want to understand the issue.
Basically there is a header which declares a static constexpr member of
a struct (simplified here for brevity):
// a.h
#pragma once
#include <array>
namespace Foo {
struct Bar {
static constexpr std::array<int, 3> blob = {1, 2, 3};
};
}
This header is included by multiple libraries. One of the libraries also
contains the definition:
// a.cpp
#include <a.h>
namespace Foo {
constexpr std::array<int, 3> Bar::blob;
}
The nm tool reports it is defined only in a single .a file and used by 3
others. Altogether there are 18 .a files.
When I now try to link my own .so, by linking it with all those static
libraries, I get a multiple definition linker error about Bar::blob. As
it seems these libraries contain cyclic interdependencies and rely on a
specific order of static initialization, some of those libraries are
listed multiple times in the linker command, but the one containing the
definition is mentioned once only.
Needless to say, I have not been able to reproduce the problem with
simplified files, it only appears with those 18 .a files with cyclic
interdependencies. Any ideas are welcome!
BTW, I'm using g++ 8.3.0