Unresolved Externals when linking against skia.dll.lib from Win32-App

32 views
Skip to first unread message

Micha

unread,
Jul 14, 2022, 2:46:12 AM7/14/22
to skia-discuss
Hi all,
I created skia.dll and associated import library skia.dll.lib using three different ways:
  1. as described here, using clang (see args.gn below)
  2. same, but using msvc
  3. using vcpkg skia package (easiest way)
All succesful, but when I create a Win32-Application (Visual Studio 22) and link against skia.dll.lib, I get unresolved exernals from ms linker. Struggled for days now with this, so any help greatly appreciated. See all details below.

------------ Source code from Visual Studio Win32-App

#include "SkiaCreateCanvas.h"

#include "skia/core/SkMatrix.h"
#include "skia/core/SkString.h"

bool SkiaCreateCanvas() {
 
  SkMatrix m = SkMatrix::Scale(1.2f, 2.3f);
  SkString s;
  return false;
}

Note that SkMatrix::Scale gets resolved with no problems, also the SkString constructor.

----------- Unresolved Externals

2>SkiaCreateCanvas.obj : error LNK2019: unresolved external symbol "bool __cdecl SkStrEndsWith(char const * const,char const * const)" (?SkStrEndsWith@@YA_NQEBD0@Z) referenced in function "public: bool __cdecl SkString::endsWith(char const * const)const " (?endsWith@SkString@@QEBA_NQEBD@Z)
2>SkiaCreateCanvas.obj : error LNK2019: unresolved external symbol "bool __cdecl SkStrEndsWith(char const * const,char)" (?SkStrEndsWith@@YA_NQEBDD@Z) referenced in function "public: bool __cdecl SkString::endsWith(char)const " (?endsWith@SkString@@QEBA_ND@Z)
2>SkiaCreateCanvas.obj : error LNK2001: unresolved external symbol "private: static void (__cdecl*const * const SkMatrix::gMapXYProcs)(class SkMatrix const &,float,float,struct SkPoint *)" (?gMapXYProcs@SkMatrix@@0QBQ6AXAEBV1@MMPEAUSkPoint@@@ZB)
2>SkiaCreateCanvas.obj : error LNK2001: unresolved external symbol "private: static void (__cdecl*const * const SkMatrix::gMapPtsProcs)(class SkMatrix const &,struct SkPoint * const,struct SkPoint const * const,int)" (?gMapPtsProcs@SkMatrix@@0QBQ6AXAEBV1@QEAUSkPoint@@QEBU2@H@ZB)

----------------- args.gn for method 1 to build skia (Release configuration)

clang_win = "C:\Program Files\LLVM"
is_official_build = true
is_component_build = true
is_debug = false
skia_use_system_expat = false
skia_use_system_libjpeg_turbo = false
skia_use_system_libpng = false
skia_use_system_libwebp = false
skia_use_system_zlib = false
skia_use_system_icu = false
skia_use_system_harfbuzz = false
skia_enable_svg = false



Micha

unread,
Jul 14, 2022, 5:30:03 AM7/14/22
to skia-discuss
We found a solution, at least for case 3 (building with vcpkg). In the Win32-project linking against skia.dll.lib, it is necessary to set SKIA_IMPLEMENTATION=0 as preprocessor definition. We used CMake config file skiaConfig.cmake provided from vcpkg skia-package for setting up the project. This used to set SKIA_IMPLEMENTATION=1, which seems to be a bug in the vcpkg port. We already reported this bug to vcpkg folks.
If you create your own skia.dll-consuming project with vcpkg, you may use the following outline for CMakeLists.txt. Be sure to install vcpkg and vcpkg skia package in ./vcpkg. 

----------- CMakeLists.txt for creating a Win32-Project linking against skia.dll.lib

project(demo-desktop VERSION 1.0 LANGUAGES CXX)

# update HINTS when using custom triplets
find_package(skia CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/vcpkg/installed/x64-windows)
find_package(unofficial-angle CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/vcpkg/installed/x64-windows)

add_executable(demo-desktop WIN32
    Win32App.cpp
    SkiaCreateCanvas.h
    SkiaCreateCanvas.cpp
    )
set_target_properties(demo-desktop PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../bin)

# Skia vcpkg seems to fail setting dll_export vs. dll_import flags correctly.
# SKIA_IMPLEMENTATION=1 is evaluated to __declspec(dll_export) when compiling
# the demo but it has to be __declspec(dll_import).
# Hence we overwrite SKIA_IMPLEMENTATION=1 by SKIA_IMPLEMENTATION=0!
get_target_property(skia_interface_defs skia INTERFACE_COMPILE_DEFINITIONS)
string(REPLACE "SKIA_IMPLEMENTATION=1" "SKIA_IMPLMENTATION=0" skia_interface_defs_fixed "${skia_interface_defs}")
set_target_properties(skia PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${skia_interface_defs_fixed}")

target_compile_features(demo-desktop PRIVATE cxx_std_17)

#skia
target_link_libraries(demo-desktop PRIVATE skia skia::skia)

Reply all
Reply to author
Forward
0 new messages