0

I have 3 projects in Visual Studio 15. The first (A) and second (B) - dynamic libraries, the third (D) - exe, which uses both libraries. The task is to link the first library statically.

The first problem I encountered is if I link to both D libraries - then the singletones that are in A, cease to be in a single copy and appear in 2 different copies in B and in D. I decided - removing the link from A, in D, because all export functions from A are now in B.

The second problem. In A there are constructions of the form:

In header:

struct A_CLASS SomeClass {
  static const double someMember;
};

in cpp:

const double SomeClass::someMember = 14;

A_CLASS is

#ifdef ( _BUILDA )
  #define A_CLASS         __declspec( dllexport )
#else
  #define A_CLASS         __declspec( dllimport )
#endif

If I try to use SomeClass::someMember in D - I receive a link error LNK2019.
dumpbin shows that in B.lib and in B.dll there is a type construct ?someMember@SomeClass@@2NA

How to fix this error?

Francuz
  • 433
  • 5
  • 13
  • 1
    Why do you want to link A statically? If you have singletons in a static library then every library or application that links to the static library gets its own copy of the singletons. That's just how static libraries work. – Alan Birtles Jun 26 '18 at 16:30
  • I understand it. There is my and a third-party project that uses A.dll. And there is a client who uses these 2 projects. The problem is that for a certain moment in my and a third-party project there can be 2 different versions of A.dll. The client loads a third-party project - A.dll is loaded into memory, when loading my project A.dll is not loaded, since it is already in memory. As a result, there are crushes and errors. I can build A.dll with a different name, but only I will use it, and the static library already has other clients. – Francuz Jun 26 '18 at 16:59
  • you can't have it both ways unfortunately. If you have two different incompatible versions of a dll they should have different names in order to avoid crashes when both are used in a single application. e.g. A_V1.dll and A_V2.dll – Alan Birtles Jun 26 '18 at 18:00

0 Answers0