Skip to content

Static linking on MSVC #90

Closed
Closed
@Swat-SomeBug

Description

@Swat-SomeBug

Hi,
When packaging the library for build2, I ran into an issue with msvc and static linking.
Based on this code snippet, it seems, only dynamic linking is supported with msvc.
Is this true?
Currently, to support static linking on windows, SIGC_BUILD needs to be passed to consumers of the library while _WINDLL should not be passed, which is a way to get SIGC_API to be empty. This seems counter intuitive and occurs because SIGC_DLL is always set to 1 with msvc.

#ifdef _WIN32
#if defined(_MSC_VER)
#define SIGC_MSC 1
#define SIGC_WIN32 1
#define SIGC_DLL 1
...
#ifdef SIGC_DLL
#if defined(SIGC_BUILD) && defined(_WINDLL)
#define SIGC_API __declspec(dllexport)
#elif !defined(SIGC_BUILD)
#define SIGC_API __declspec(dllimport)
#else
#define SIGC_API
#endif
#else /* !SIGC_DLL */
#define SIGC_API
#endif /* !SIGC_DLL */

To support both dynamic and static linking, could passing SIGC_DLL on the command line, be considered. The code snippet would look as below:

#ifdef SIGC_DLL
#ifdef SIGC_BUILD
#define SIGC_API __declspec(dllexport)
#else
#define SIGC_API __declspec(dllimport)
#endif
#else /* !SIGC_DLL */
#define SIGC_API
#endif /* !SIGC_DLL */

Basically the snippet above requires the user to pass -DSIGC_BUILD and -DSIGC_DLL when building a shared library under windows and only -DSIGC_DLL when consuming the library as a DLL. _WINDLL is unnecessary in this case. For all other cases (static lib on windows or static/dynamic on any other platform), no defines are needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions