shared-libraries - 如何在chrome的gn文件中包含共享库?

标签 shared-libraries static-libraries chromium ninja gn

(Q1)我有一个 test.so 有一些我需要使用的功能。我已经调查了一段时间但没有答案。任何人都可以就如何在 Chromium 项目的 gn 文件中包含共享库提出一些建议吗?非常感谢。

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

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中编写使用共享库的源代码?谢谢。

最佳答案

(Q1)Could anyone have some advise of how to include a shared library in gn file of chromium project?



通常,您可以使用 lib_dirs 指定库目录和图书馆 libs .您的 BUILD.gn文件可以是这样的:
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" ]

}

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



如果你想从add.so的源代码中得到一个共享库,你可以写一个BUILD.gn像这样的文件:
shared_library("libadd.so") {
  include_dirs = []
  sources = [
    "/path/to/sources",
  ]
}

您可以使用 gn help shared_library更多细节。

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

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

关于shared-libraries - 如何在chrome的gn文件中包含共享库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49102921/

相关文章:

c++ - 使用 Waf 编译时无法正确链接库

php - symfony2 : how to integrate a php library which is not a bundle

c++ - 来自c++中动态加载库的指针

electron - 如何检测 Chrome /Electron 何时完成缩放?

node.js - 通过nodejs获取操作系统显示枚举

c - 在公共(public)头文件中包含条件是否被认为是好的做法?

c++ - 将静态类与友元函数链接时出现奇怪的错误

c++ - 如何在 VS2015 中将外部库依赖项链接到一个静态库文件中

c++ - 在 visual studio 2012 (C++) 中使用 .lib

electron - 防止用户在 Electron 中退出全屏模式到窗口模式?