blink1-tool icon indicating copy to clipboard operation
blink1-tool copied to clipboard

Building blink1 for Windows with MSVC

Open YevYar opened this issue 5 months ago • 5 comments

Hi,

First of all, thanks for open-sourcing blink1 - it's a really helpful tool.

I noticed that the project currently provides a Makefile-based build system that targets GCC/MinGW on Windows, but there’s no official support for building the blink1-lib with MSVC or using CMake. However, there is a hidapi.sln file to build HIDAPI.

Would you mind sharing the reason behind this choice? In particular, I’m wondering if ABI compatibility with MSVC was considered when using a MinGW-built DLL in MSVC-based projects.

Thanks again for your work on this!

YevYar avatar Jul 29 '25 15:07 YevYar

Hi and thanks!

Correct, we don't have a blink1-lib .sln file, but hidapi has one.

The current blink1-lib & blink1-tool build setup is designed for unix-like systems, with a few exceptions to let it build on Windows with MSYS2. The hidapi.sln provided by hidapi should create a DLL that will work when integrating blink1-lib into your app. Apologies, but I don't have an MSVC-specific solution. Our Windows customers typically are writing in C# and use the Sleddog/blink1 library (also available on NuGet).

todbot avatar Jul 29 '25 17:07 todbot

Thank you for the response! I built the blink1-lib.lib and dll. The output was the following:

make
Building blink1-tool for OS=windows BLINK1_VERSION=v20220126-windows-x86_64 USBLIB_TYPE=HIDAPI
Type 'make help' for other build products
Not updating submodules
gcc -DUSE_HIDAPI -I./hidapi/hidapi -Wall -std=gnu99 -DBLINK1_VERSION=\"""v20220126"-windows-"x86_64""\" -c blink1-lib.c -o blink1-lib.o
gcc -DUSE_HIDAPI -I./hidapi/hidapi -Wall -std=gnu99 -DBLINK1_VERSION=\"""v20220126"-windows-"x86_64""\"   -c -o blink1-tool.o blink1-tool.c
gcc -DUSE_HIDAPI -I./hidapi/hidapi -Wall -std=gnu99 -DBLINK1_VERSION=\"""v20220126"-windows-"x86_64""\" -c blink1-tool.c -o blink1-tool.o
gcc -DUSE_HIDAPI -I./hidapi/hidapi -Wall -std=gnu99 -DBLINK1_VERSION=\"""v20220126"-windows-"x86_64""\"  ./hidapi/windows/hid.o blink1-lib.o -lsetupapi -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lws2_32 blink1-tool.o -o blink1-tool.exe
gcc -shared -o blink1-lib.dll -Wl,--add-stdcall-alias -Wl,--export-all-symbols,--output-def,blink1-lib.def,--out-implib,blink1-lib.a -DUSE_HIDAPI -I./hidapi/hidapi -Wall -std=gnu99 -DBLINK1_VERSION=\"""v20220126"-windows-"x86_64""\" ./hidapi/windows/hid.o blink1-lib.o -lsetupapi -Wl,--enable-auto-import -static-libgcc -static-libstdc++ -lws2_32
lib /machine:x64 /def:blink1-lib.def
Microsoft (R) Library Manager Version 14.39.33523.0
Copyright (C) Microsoft Corporation.  All rights reserved.

   Creating library blink1-lib.lib and object blink1-lib.exp

As I understood, the hidapi was statically linked in the generated blink1-lib.lib/dll. When I added the generated files in my app and started it, I saw no error message about missed hidapi.dll. So, I assume hidapi is used in the generated files.

The hidapi.sln provided by hidapi should create a DLL that will work when integrating blink1-lib into your app.

Could you please clarify when I should build hidapi using hidapi.sln and how I should link it in my project?

YevYar avatar Jul 29 '25 21:07 YevYar

Apologies, I wasn't sure how your project was set up. Since you referenced the hidapi.sln, I thought you were using it. If you can use the blink1-lib.{h,lib} and blink1-lib.exp files then I assume you don't a .sln file.
(I've not done much MSVC development so your input would be greatly helpful here)

todbot avatar Jul 29 '25 22:07 todbot

I'll try to check it tomorrow. Is there any license restrictions to link hidapi statically, when building blink1-lib?

YevYar avatar Jul 29 '25 22:07 YevYar

No license restrictions on hidapi. It's triple licensed, pick the one you want.

todbot avatar Jul 29 '25 23:07 todbot