首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在OSX上使用Skia中的Skia

在OSX上使用Skia中的Skia
EN

Stack Overflow用户
提问于 2018-11-01 02:54:12
回答 1查看 1.3K关注 0票数 3

我想在OSX上使用Skia和SDL2。我成功地安装了SDL2,并在Clion的一个项目中测试了它,它运行得很好。然后我在Skia的官方网站上学习了教程。我编译了它,并把它放在我的克里恩项目,它没有工作!我检查了好几次,但不知道为什么失败了。

这是我关于测试项目的配置。

我给Skia建的命令:

代码语言:javascript
复制
$ cd skia
$ python tools/git-sync-deps
$ bin/gn gen out/Release --args="is_official_build=true is_component_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 extra_cflags_cc=[\"-frtti\"]"
$ ninja -C out/Release skia

它生成两个静态库libskia.alibpathkit.a

这个屏幕截图展示了我是如何配置我的项目的。

这是我的CMakeLists.txt

代码语言:javascript
复制
cmake_minimum_required(VERSION 3.12)
project(skia_tutorial)

set(CMAKE_CXX_STANDARD 11)

set(SKIA_SDK "${CMAKE_SOURCE_DIR}/SKIA_SDK")

include_directories(
    ${SKIA_SDK}/include
    ${SKIA_SDK}/include/android
    ${SKIA_SDK}/include/atlastext
    ${SKIA_SDK}/include/c
    ${SKIA_SDK}/include/codec
    ${SKIA_SDK}/include/config
    ${SKIA_SDK}/include/core
    ${SKIA_SDK}/include/effects
    ${SKIA_SDK}/include/encode
    ${SKIA_SDK}/include/gpu
    ${SKIA_SDK}/include/gpu/gl
    ${SKIA_SDK}/include/gpu/mock
    ${SKIA_SDK}/include/gpu/mtl
    ${SKIA_SDK}/include/gpu/vk
    ${SKIA_SDK}/include/pathops
    ${SKIA_SDK}/include/ports
    ${SKIA_SDK}/include/private
    ${SKIA_SDK}/include/svg
    ${SKIA_SDK}/include/utils
    ${SKIA_SDK}/include/utils/mac
    ${SKIA_SDK}/include/views)


add_executable(skia_tutorial main.cpp)

target_link_libraries(skia_tutorial ${SKIA_SDK}/libskia.a)
target_link_libraries(skia_tutorial ${SKIA_SDK}/libpathkit.a)

set(CMAKE_MODULE_PATH "/usr/local/Cellar/sdl2/2.0.8/lib/cmake")
find_package(SDL2 REQUIRED)
if (SDL2_FOUND)
    include_directories(${SDL2_INCLUDE_DIR})
    target_link_libraries(skia_tutorial ${SDL2_LIBRARIES})
endif()

这是我的main.cpp

代码语言:javascript
复制
#include <SkBitmap.h>
#include <SkTypeface.h>
#include <SkCanvas.h>
#include <SDL2/SDL.h>

//RGBA
struct RGBA {
    //Red
    Uint32 rmask = 0x00ff0000;
    //Green
    Uint32 gmask = 0x0000ff00;
    //Blue
    Uint32 bmask = 0x000000ff;
    //Alpha
    Uint32 amask = 0xff000000;
};


SkBitmap draw(int w, int h) {

    SkBitmap bitmap;

    bitmap.setInfo(SkImageInfo::Make(w, h, kBGRA_8888_SkColorType, kOpaque_SkAlphaType));

    bitmap.allocPixels();

    SkCanvas canvas(bitmap);

    SkPaint paint;

    canvas.clear(SK_ColorWHITE);

    paint.setAntiAlias(true);

    paint.setARGB(255, 255, 0, 0);

    canvas.drawCircle(80, 80, 40, paint);

    canvas.drawLine(0, 280, w, 280, paint);

    paint.setTextSize(60);

    canvas.drawString("Hello Skia", 300, 150, paint);

    return bitmap;
}


SDL_Rect create_rect(SDL_Surface *surface) {

    SDL_Rect src = { 0, 0, surface->w, surface->h };

    return src;
}


int main(int args, char *argv[]) {

    SDL_Window *window;

    SDL_Surface *surface;

    SDL_Renderer *renderer;

    SDL_Texture *texture;

    SkBitmap bitmap;

    RGBA rgba;

    SDL_Rect rect;

    int width = 800;
    int height = 480;

    SDL_Init(SDL_INIT_VIDEO);

    window = SDL_CreateWindow("Hello Skia", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height,
                              SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
    if (window == NULL) {
        return -1;
    }

    bitmap = draw(width, height);
    surface = SDL_CreateRGBSurfaceFrom(bitmap.getPixels(), width, height, 32, width * 4, rgba.rmask, rgba.gmask,
                                       rgba.bmask, rgba.amask);
    rect = create_rect(surface);
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    SDL_RenderClear(renderer);
    texture = SDL_CreateTextureFromSurface(renderer, surface);
    SDL_RenderCopy(renderer, texture, NULL, &rect);
    SDL_RenderPresent(renderer);
    SDL_Delay(5000);
    SDL_FreeSurface(surface);
    SDL_DestroyTexture(texture);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

但克莱恩的表演

代码语言:javascript
复制
[ 50%] Linking CXX executable skia_tutorial
Undefined symbols for architecture x86_64:
      "_CFArrayCreate", referenced from:
.....
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [CMakeFiles/skia_tutorial.dir/build.make:86: skia_tutorial] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/skia_tutorial.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/skia_tutorial.dir/rule] Error 2
gmake: *** [Makefile:118: skia_tutorial] Error 2

显然,它猜测CMakeLists.txt有什么问题。但是,我没有发现任何错误..。

请帮我解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2018-11-01 03:48:41

我在如何将C++项目的Skia库与XCode链接中找到了一些东西,在Add Mac特定的Skia依赖项中,我在CMakeLists.txt中添加了以下规范,并且它工作了!

代码语言:javascript
复制
if (APPLE)
    target_link_libraries(skia_tutorial "-framework CoreServices")
    target_link_libraries(skia_tutorial "-framework CoreGraphics")
    target_link_libraries(skia_tutorial "-framework CoreText")
    target_link_libraries(skia_tutorial "-framework CoreFoundation")
endif()
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53094613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档