Skip to content

Add dllexport/dllimport to make it easier to use Sonic as a DLL #54

@gexgd0419

Description

@gexgd0419

There's no __declspec(dllexport) or __declspec(dllimport) in the header file, so Sonic cannot be used directly as a DLL without modification, because nothing would be exported. Compiling a Windows DLL requires functions to be explicitly exported.

A .def file can be added to export the functions as a workaround. However, the same header file is usually used when importing the functions as well. Without __declspec(dllimport), the compiler will assume that it is a regular extern function, and some optimizations for imported functions will not be applied.

To support compiling to both DLL and static library, #ifdef can be used to check a specific macro, for example SONIC_DLL. If not defined, __declspec(dllexport) and __declspec(dllimport) will not be added to keep the original behavior. Those who want to use Sonic as a DLL would have to predefine this macro.

There's a related pull request #27 but it hasn't been merged or closed for a long time. So @waywardgeek what's your thought about that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions