Skip to content

Unable to build shared library on Windows (MinGW-w64) #2225

@brechtsanders

Description

@brechtsanders

When building highway 1.2.0 on Windows using MinGW-w64 the shared build fails with the following error:

hwy/contrib/thread_pool/topology.cc:67:20: error: function 'bool hwy::HaveThreadingSupport()' definition is marked dllimport

When looking at this section in hwy/highway_export.h:

#if !defined(HWY_SHARED_DEFINE)
#define HWY_DLLEXPORT
#define HWY_CONTRIB_DLLEXPORT
#define HWY_TEST_DLLEXPORT
#else  // !HWY_SHARED_DEFINE

#ifndef HWY_DLLEXPORT
#if defined(hwy_EXPORTS)
/* We are building this library */
#ifdef _WIN32
#define HWY_DLLEXPORT __declspec(dllexport)
#else
#define HWY_DLLEXPORT __attribute__((visibility("default")))
#endif
...

and this section in CMakeLists.txt:

if("${HWY_LIBRARY_TYPE}" STREQUAL "SHARED")
  set(DLLEXPORT_TO_DEFINE "HWY_SHARED_DEFINE")
else()
  set(DLLEXPORT_TO_DEFINE "HWY_STATIC_DEFINE")
endif()

it's clear that set(DLLEXPORT_TO_DEFINE "HWY_SHARED_DEFINE") causes HWY_DLLEXPORT to be defined as nothing instead of __declspec(dllexport).

I was able to build successfully after changing CMakeLists.txt so HWY_SHARED_DEFINE is not defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions