lsquic icon indicating copy to clipboard operation
lsquic copied to clipboard

How to build Dynamic dll in Windows?

Open ellishawn opened this issue 4 years ago • 8 comments

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?

ellishawn avatar Sep 19 '21 12:09 ellishawn

We are a Linux shop, cannot help much on that. but pull request on this are welcome.

litespeedtech avatar Sep 19 '21 13:09 litespeedtech

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.

ellishawn avatar Sep 19 '21 21:09 ellishawn

I have done it with visual studio 2017 and vcpkg.

wangweiwei1188 avatar Sep 22 '21 03:09 wangweiwei1188

Can you kindly give us some step-by-step guide on what you did just so we don't repeat work?

Thank you!

ellishawn avatar Sep 23 '21 20:09 ellishawn

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

TYoungSL avatar Nov 23 '21 04:11 TYoungSL

Might address all of this in PR #350.

TYoungSL avatar Dec 14 '21 18:12 TYoungSL

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.

litespeedtech avatar Dec 14 '21 20:12 litespeedtech

Linking to #139 - maybe close this issue and defer to that one.

TYoungSL avatar Dec 15 '21 17:12 TYoungSL