本文介绍了如何在Chrome的gn文件中包含共享库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(Q1)我有一个test.so,其中包含一些我需要使用的功能.我调查了一段时间,但没有答案.有人可以建议在铬项目的gn文件中包含共享库吗?非常感谢.

(Q1)I have a test.so with some functions that I need to use.I've surveyed for a while but no answers. Could anyone have some advise of how to include a shared library in gn file of chromium project? Many thanks.

下面是我的gn文件的内容:

Below is the content of my gn file:

import("//third_party/WebKit/Source/core/core.gni")

blink_core_sources("frame") {
 sources = [
    "csp/CSPSource.h",
    "csp/ContentSecurityPolicy.cpp",
    "csp/ContentSecurityPolicy.h",
    "csp/MediaListDirective.cpp",
    "csp/MediaListDirective.h",
    "csp/SourceListDirective.cpp",
    "csp/SourceListDirective.h",

    // my created file
    "HelloWorld.h",
    "HelloWorld.cpp",   // Will use the function of provided in add.so
    "add.h"
  ]

  deps = [ ":add.so" ]

}

(Q2)另一个问题是:如果我有add.so的源代码,我应该如何在gn中编写以使用共享库的源代码?谢谢.

(Q2)Another question is: If I have source code of add.so, how should I write in gn to use the source code of the shared library? Thanks.

推荐答案

通常,您可以使用 lib_dirs 指定库目录,并使用 libs 指定库.您的 BUILD.gn 文件可以如下所示:

Typicall you can specify library directory with lib_dirs and libraries with libs. Your BUILD.gn file can be like this:

import("//third_party/WebKit/Source/core/core.gni")

blink_core_sources("frame") {
 sources = [
    "csp/CSPSource.h",
    "csp/ContentSecurityPolicy.cpp",
    "csp/ContentSecurityPolicy.h",
    "csp/MediaListDirective.cpp",
    "csp/MediaListDirective.h",
    "csp/SourceListDirective.cpp",
    "csp/SourceListDirective.h",

    // my created file
    "HelloWorld.h",
    "HelloWorld.cpp",   // Will use the function of provided in add.so
    "add.h"
  ]

  lib_dirs = [ "//path/to/add.so" ]
  libs = [ "add" ]

}

如果要从add.so的源代码获取共享库,可以编写如下的 BUILD.gn 文件:

If you want to get a shared library from source code of add.so, you can write a BUILD.gn file like this:

shared_library("libadd.so") {
  include_dirs = []
  sources = [
    "/path/to/sources",
  ]
}

您可以使用 gn help shared_library 了解更多详细信息.

You can use gn help shared_library for more details.

然后您可以像Q(1)一样使用共享库.

And then you can use the shared library just like Q(1).

最后,我建议您使用 gn帮助查看有关gn构建系统的更多详细信息.

Finally, I recommand you to use gn help to see more details about gn build system.

这篇关于如何在Chrome的gn文件中包含共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 22:58