Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eugeneo opened this issue Nov 27, 2024 · 6 comments
Open

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

eugeneo opened this issue Nov 27, 2024 · 6 comments

Comments

@eugeneo
Copy link

eugeneo commented Nov 27, 2024

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",
    ],
)
@eugeneo
Copy link
Author

eugeneo commented Nov 27, 2024

I tried the latest version, does not work.

@jan-wassenberg
Copy link
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
Copy link
Author

eugeneo commented Dec 2, 2024

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
Copy link
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
Copy link
Author

eugeneo commented Dec 2, 2024

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

@chinwobble
Copy link

chinwobble commented Dec 8, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants