(Q1)任何人都可以对如何在 chromium 项目的 gn 文件中包含共享库有一些建议吗?
通常您可以指定库目录lib_dirs
和图书馆libs
. Your 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)如果我有add.so的源代码,我应该如何在gn中编写才能使用共享库的源代码?
如果你想从add.so的源代码中获取共享库,你可以写一个BUILD.gn
像这样的文件:
shared_library("libadd.so") {
include_dirs = []
sources = [
"/path/to/sources",
]
}
您可以使用gn help shared_library
更多细节。
然后就可以像Q(1)一样使用共享库了。
最后推荐大家使用gn help
查看有关 gn 构建系统的更多详细信息。