如何使用Xcode链接C ++项目的Skia库 [英] How to link the Skia library for a C++ project with Xcode

查看:308
本文介绍了如何使用Xcode链接C ++项目的Skia库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Skia是一个图形库(skia.org ). 该文档介绍了通过git克隆项目后如何构建库.但是到目前为止,该文档尚不清楚,如何使用使用Skia库的Xcode构建C ++项目.

Skia is a graphics library (skia.org). The documentation explains how to build the library after cloning the project via git. But the documentation is unclear as of this date, how to build a C++ project with Xcode which uses the Skia library.

我尝试了文档中的所有内容,但是找不到在C ++ Xcode项目中如何链接Skia库的方法.

I tried all what is written in the documentation, but can't find a way of how to link the skia library in a C++ Xcode project.

推荐答案

如何解决问题:

添加图书馆搜索路径

此屏幕截图显示了如何以及在何处执行这些步骤:

How to Solve the Problem:

Add Library Search Path

This screenshot shows how and where to do these steps:

添加Skia库路径图像

  1. 在项目导航器中,单击项目的图标.
  2. 在主窗口分区左侧的项目导航器旁边的面板中:再次单击项目图标以打开项目的全局信息和设置.
  3. 在主窗口分区顶部的导航栏中:单击构建设置"
  4. 确保将下面的视图过滤器设置为所有"和组合",这样您就不会错过任何设置.
  5. 在选项搜索表单中,输入图书馆搜索路径"以找到图书馆搜索路径"的条目
  6. 双击条目库搜索路径"条目以接收弹出窗口,您可以在其中指定要链接的库的搜索路径.
  7. 在弹出窗口中,双击一个空行,以输入到您先前构建的libskia.a库文件的路径. (注意:我使用static build选项创建了一个静态库.如果要链接动态.so库,设置会略有不同)
  1. In the Project Navigator click the icon of your project.
  2. In the panel on the left of the main window division next to the Project Navigator: Click on to your project icon again to open project global info and settings.
  3. In the navigation bar on top of the main window division: Click on "Build Settings"
  4. Make sure the view filters below are set to "All" and "Combined" so you don't miss any settings.
  5. In the option search form enter "Library search path" to find the entry for "Library Search Paths"
  6. Double klick the Entry "Library Search Paths" to receive the popup in which you can specify search paths to libraries which shall be linked.
  7. Inside the popup double click an empty line to enter the path to your libskia.a library file which you built earlier. (Note: I used the static build option to create a static library. If you want to link a dynamic .so library, the settings are slightly different)

与libskia.a静态链接

以下步骤应在与之前步骤相同的主窗口内执行.

Statically Link with libskia.a

The following steps should be performed inside the same main window division as the steps before.

  1. 在选项搜索表单中,输入其他链接"以查找其他链接器标志"的条目
  2. 添加标记-lskia以在构建项目时静态链接libskia.a库.
  1. In the option search form enter "other link" to find the entry for "Other Linker Flags"
  2. Add the Flag -lskia to statically link the libskia.a library when building the project.

确保已设置标题包含路径

以下步骤应在与之前步骤相同的主窗口内执行.

Make Sure Header Include Paths Are Set

The following steps should be performed inside the same main window division as the steps before.

  1. 在选项搜索表单中,输入标题搜索"以找到标题搜索路径"的条目
  2. 双击"Header Search Paths"条目以接收弹出窗口,您可以在其中指定要包括的头文件的搜索路径.对于下面的示例,添加"[到您的Skia目录的路径]/skia/include"并将右侧的搜索模式设置为递归"就足够了.

添加Skia的Mac OSX特定依赖项

以下步骤应在与之前步骤相同的主窗口内执行. 此屏幕快照显示了在哪里执行这些步骤:

Add Mac OSX Specific Dependencies of Skia

The following steps should be performed inside the same main window division as the steps before. This screenshot shows where to do these steps:

添加Skia Mac OSX特定依赖项图像

  1. 在主窗口分区左侧的项目导航器旁边的面板中:单击目标以打开特定于目标的信息和设置.
  2. 在主窗口分区顶部的导航栏中:单击构建阶段"
  3. 在将二进制文件与库链接"下,单击+符号.
  4. 添加以下Mac OSX特定的Skia依赖项:
    • CoreServices.framework
    • CoreGraphics.framework
    • CoreText.framework
    • CoreFoundation.framework
  1. In the panel on the left of the main window division next to the Project Navigator: Click on to your target to open target specific info and settings.
  2. In the navigation bar on top of the main window division: Click on "Build Phases"
  3. Under "Link Binary With Libraries", click the + sign.
  4. Add the following Mac OSX specific Skia dependencies:
    • CoreServices.framework
    • CoreGraphics.framework
    • CoreText.framework
    • CoreFoundation.framework

测试代码

您可以使用以下示例代码测试这些设置:

Testcode

You may test these settings with the following example code:

#include "SkSurface.h"
#include "SkPath.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImage.h"
#include "SkStream.h"

int main (int argc, char * const argv[]) {
  // hard coded example program parameters
  const char filePath[] = "/Users/[yourUserName]/Desktop/skiaTestImage.png";
  int width = 256;
  int height = 256;

  // create canvas to draw on
  sk_sp<SkSurface> rasterSurface = SkSurface::MakeRasterN32Premul(width, height);
  SkCanvas* canvas = rasterSurface->getCanvas();

  // creating a path to be drawn
  SkPath path;
  path.moveTo(10.0f, 10.0f);
  path.lineTo(100.0f, 0.0f);
  path.lineTo(100.0f, 100.0f);
  path.lineTo(0.0f, 100.0f);
  path.lineTo(50.0f, 50.0f);
  path.close();

  // creating a paint to draw with
  SkPaint p;
  p.setAntiAlias(true);

  // clear out which may be was drawn before and draw the path
  canvas->clear(SK_ColorWHITE);
  canvas->drawPath(path, p);

  // make a PNG encoded image using the canvas
  sk_sp<SkImage> img(rasterSurface->makeImageSnapshot());
  if (!img) { return 1; }
  sk_sp<SkData> png(img->encodeToData());
  if (!png) { return 1; }

  // write the data to the file specified by filePath
  SkFILEWStream out(filePath);
  (void)out.write(png->data(), png->size());

  return 0;
}

附录

使用终端进行编译

您可以通过编写make文件或直接在终端中调用g ++编译器来实现相同目的.这是一个示例:

Appendix

Compiling With the Terminal

You may accomplish the same by writing a make file or by invoking the g++ compiler directly in the terminal. Here is an example:

g++ -std=c++11 main.cpp -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework CoreServices -L[path_to_your_Skia_library]/skia/out/Static_m58 -lskia -I[path_to_your_Skia_library]/skia/include/core -I[path_to_your_Skia_library]/skia/include/config -I[path_to_your_Skia_library]/skia/include/utils -I[path_to_your_Skia_library]/skia/third_party/externals/sdl/include -I[path_to_your_Skia_library]/skia/include/gpu -I[path_to_your_Skia_library]/skia/src/gpu -o main

发现所有这些东西花了我大约12个小时.如果您对最终导致解决方案的步骤感兴趣,我将在此处进行解释.请让我知道.

Finding all this stuff out took me around 12 hours. If you are interested in the steps which finally lead to the solution, I'll explain them here. Just let me know.

这篇关于如何使用Xcode链接C ++项目的Skia库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆