Home > Software engineering >  Skia-for-Aseprite libs: how to compile for a DEBUG-build project in Visual Studio?
Skia-for-Aseprite libs: how to compile for a DEBUG-build project in Visual Studio?

Time:12-12

I'm building static C libs off of github. Specifically, the Skia-for-Aseprite libs (link is to the github page). I'm following the windows compilation instructions written up in the git repo's readme. The instructions have you compile the libs using LLVM/CLANG and the Ninja build system. Afterwards they work just fine when linked to a project in Visual Studio 2020 (my main IDE).

The problem is that the instructions only say how to compile RELEASE-build libs, whereas I need to compile DEBUG-build libs so that I can use the debugger in VS2020. So I changed the final commands to try and compile a DEBUG-build. I changed them from:

gn gen out/Release-x64 --args="is_debug=false is_official_build=true skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false target_cpu=""x64"" cc=""clang"" cxx=""clang  "" clang_win=""c:\deps\llvm"" win_vc=""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC"" extra_cflags=[""-MT""]"
ninja -C out/Release-x64 skia modules

to:

gn gen out/Debug-x64 --args="is_debug=true is_official_build=false skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false target_cpu=""x64"" cc=""clang"" cxx=""clang  "" clang_win=""c:\dev\llvm"" win_vc=""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC"" extra_cflags=[""-MT""]"
ninja -C out/Debug-x64 skia modules

Changes made, being:

  • "is_debug=false" to "is_debug=true"
  • "is_official_build=true" to "is_official_build=false"
  • output directory "Release-x64" to "Debug-x64"

It builds fine, and the lib files are notably bigger, suggesting that they contain debug info. However, when statically linking them into a DEBUG-build project in VS2020, I get lots of this error:

LNK2038 - mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease'

When I link the DEBUG-build libs into a RELEASE-build project in VS, it builds and runs without errors, suggesting that VS2020 sees the DEBUG-build libs as RELEASE-build libs, despite the changes listed above.

Does anyone have an idea as to what is needed to build these libs in such a way that they work in a DEBUG-build project in VS2020?

Thanks for any help you can provide.

CodePudding user response:

I've found a solution! Apparently this solution is applicable to any LLVM DEBUG-built library to be used in Visual studio.

The line in my question that triggered the compile (which started with "gn gen") ends with:

extra_cflags=[""-MT""]"

To get the compiled library recognizable as DEBUG-mode in visual studio, the "-MT" needs to be changed to "-MTd".

The other changes listed in the question are most likely necessary too. Most notably:

  • "is_debug=false" to "is_debug=true"
  • "is_official_build=true" to "is_official_build=false"
  • Related