lsquic
lsquic copied to clipboard
How to build Dynamic dll in Windows?
I've tried a few things and can't seem to build the library as a dynamic ".dll" in Windows. I've done this in Mac. Are there any instructions for building Windows as a dynamic library?
We are a Linux shop, cannot help much on that. but pull request on this are welcome.
If someone could point me to the right incantations to say to cmake to get it to build a dynamic library instead of static I would be happy to submit it.
I’ve tried inserting the command parameter from the *nix build instructions on building a dynamic library, setting “-DLSQUIC_SHARED_LIB=1” in the Windows build command but that seems to make the Windows version unhappy with all kinds of build errors.
I have done it with visual studio 2017 and vcpkg.
Can you kindly give us some step-by-step guide on what you did just so we don't repeat work?
Thank you!
Assuming you build from a 'build' subdirectory,
cmake -G "Visual Studio 17 2022" \
-DCMAKE_GENERATOR_PLATFORM=x64 \
-DLSQUIC_SHARED_LIB=ON \
-DBUILD_SHARED_LIBS=ON \
-DVCPKG_TARGET_TRIPLET=x64-windows \
-DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_TOOLCHAIN_FILE=C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake" \
"-DBORINGSSL_DIR=C:\path\to\boringssl\build" \
"-DBORINGSSL_INCLUDE=C:\path\to\boringssl\include" \
"-DZLIB_INCLUDE_DIR=C:\path\to\vcpkg\installed\x64-windows-static\include" \
"-DZLIB_LIB=C:\path\to\vcpkg\installed\x64-windows-static\lib\zlib.lib" \
"-DEVENT_INCLUDE_DIR=C:\path\to\vcpkg\installed\x64-windows-static\include" \
"-DEVENT_LIB=C:\path\to\vcpkg\installed\x64-windows-static\lib\event.lib" \
"-DPCRE_LIB=C:\path\to\vcpkg\installed\x64-windows-static\lib\pcre.lib" \
"-DPCREPOSIX_LIB=C:\path\to\vcpkg\installed\x64-windows-static\lib\pcreposix.lib" \
..
In CMakeLists.txt, you need to change this bit;
IF(LSQUIC_SHARED_LIB)
SET(LIB_SUFFIX .so)
ELSE()
SET(LIB_SUFFIX .a)
ENDIF()
It probably should be;
IF (MSVC)
IF(LSQUIC_SHARED_LIB)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES CACHE BOOL "Export all symbols") # maybe necessary
SET(LIB_SUFFIX .dll)
ELSE()
SET(LIB_SUFFIX .lib)
ENDIF()
ELSE()
IF(LSQUIC_SHARED_LIB)
SET(LIB_SUFFIX .so)
ELSE()
SET(LIB_SUFFIX .a)
ENDIF()
ENDIF()
This will let you build lsquic.dll without (further) code changes, but now you will probably still have some linkage problems when building the executables.
At least now you can do this though,
msbuild /p:Configuration=Release src\liblsquic\lsquic.vcxproj
Might address all of this in PR #350.
Thanks for the contribution, still wait for the CI result. Once it is passed, will merge it. If it also depends on pull request to ls-qpack project, the CI failure need to be addressed over there as well.
Linking to #139 - maybe close this issue and defer to that one.