Skip to content

Unable to link with Bazel using VC++2022 #2390

Open
@eugeneo

Description

@eugeneo
Contributor

I have a project setup with Bazel, it builds fine except for VC++. VC++ complains it can't find hwy::Abort(char const *,int,char const *,...):

primitives.lib(primitives.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl hwy::Abort(char const *,int,char const *,...)" (__imp_?Abort@hwy@@YAXPEBDH0ZZ) referenced in function "public: static float __cdecl hwy::N_SSE2::Dot::Compute<1,struct hwy::N_SSE2::Simd<float,4,0>,float>(struct hwy::N_SSE2::Simd<float,4,0>,float const * __restrict const,float const * __restrict const,unsigned __int64)" (??$Compute@$00U?$Simd@M$03$0A@@N_SSE2@hwy@@M@Dot@N_SSE2@hwy@@SAMU?$Simd@M$03$0A@@12@QEIBM1_K@Z)
bazel-out\x64_windows-fastbuild\bin\test\math\primitives_test.exe : fatal error LNK1120: 1 unresolved externals

Same project compiles/links fine with GCC and Clang on Mac and Linux.

I import Highway as a Bazel module:

bazel_dep(name = "highway", version = "1.2.0")

Dependencies:

cc_library(
    name = "primitives",
    srcs = ["primitives.cc"],
    hdrs = ["primitives.h"],
    deps = [
        "@abseil-cpp//absl/log:log",
        "@highway//:dot",
        "@highway//:hwy",
    ],
)

Activity

eugeneo

eugeneo commented on Nov 27, 2024

@eugeneo
ContributorAuthor

I tried the latest version, does not work.

jan-wassenberg

jan-wassenberg commented on Nov 27, 2024

@jan-wassenberg
Member

Interesting.. I see that abort.cc is in the "hwy" target, and that we have HWY_DLLEXPORT annotations on both the declaration and definition, which are the usual causes of this.

We actually ask for a DLL build in the open source version: https://github.com/google/highway/blob/master/BUILD#L139C25-L139C42
But internally and in CI, this is disabled. Removing the HWY_SHARED_DEFINE should avoid the problem.

hm, I suspect DLL builds are not worth the trouble for Highway, but it's probably worse to disable them now everywhere and cause confusion for projects already using them.

eugeneo

eugeneo commented on Dec 2, 2024

@eugeneo
ContributorAuthor

Does this need a fix in highway or can I configure build in my project? My project is a library itself so I would rather link Highway statically.

jan-wassenberg

jan-wassenberg commented on Dec 2, 2024

@jan-wassenberg
Member

You should be able to get a static build by setting the CMake variable HWY_FORCE_STATIC_LIBS, see

if (NOT BUILD_SHARED_LIBS OR HWY_FORCE_STATIC_LIBS)
:)

eugeneo

eugeneo commented on Dec 2, 2024

@eugeneo
ContributorAuthor

I'm using Bazel... I will see if I can set that flag somehow in Bazel.

chinwobble

chinwobble commented on Dec 8, 2024

@chinwobble

I'm getting the same issue when installing highway using vcpkg as well.

I tried adding the following to my CMakeLists.txt but it didn't work.

find_package(hwy CONFIG REQUIRED)
set(HWY_FORCE_STATIC_LIBS ON)
set(HWY_LIBRARY_TYPE "STATIC")
[build] sequence.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __vectorcall hwy::FreeAlignedBytes(void const *,void (__vectorcall*)(void *,void *),void *)" (__imp_?FreeAlignedBytes@hwy@@YQXPEBXP6QXPEAX1@Z1@Z) referenced in function "public: void __cdecl hwy::AlignedFreer::operator()<unsigned char>(unsigned char *)const " (??$?RE@AlignedFreer@hwy@@QEBAXPEAE@Z)
eugeneo

eugeneo commented on Dec 23, 2024

@eugeneo
ContributorAuthor

I made it work for me by undefing the symbol before including the Highway. Could not figure out how to do it on the build level or what to adjust in Highway...

#undef HWY_SHARED_DEFINE
#include "hwy/highway.h"
#include "hwy/contrib/dot/dot-inl.h"
#include "hwy/contrib/math/math-inl.h"

I believe there should be a better fix. I have Windows env setup now for Highway build so I would not mind working on this, if there's any suggestion on the direction.

jan-wassenberg

jan-wassenberg commented on Jan 6, 2025

@jan-wassenberg
Member

@chinwobble is this the only HWY_DLLEXPORT symbol you are using and that is missing? Isn't there also AllocateAlignedBytes?

@eugeneo glad this workaround works, though I agree it's suboptimal. Bazel is a little strange with static builds. AFAIK it is not possible to ask for that within the BUILD file itself. Have you tried running Bazel with --dynamic_mode=off flag?

jan-wassenberg

jan-wassenberg commented on Jul 10, 2025

@jan-wassenberg
Member

Closing, feel free to reopen if you'd like to continue the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @eugeneo@jan-wassenberg@chinwobble

        Issue actions

          Unable to link with Bazel using VC++2022 · Issue #2390 · google/highway