Skip to content

Instantly share code, notes, and snippets.

@patricksuo
Last active April 23, 2019 18:42
Show Gist options
  • Save patricksuo/5b76ab2ff2e84023c2caf84305b3d3a6 to your computer and use it in GitHub Desktop.
Save patricksuo/5b76ab2ff2e84023c2caf84305b3d3a6 to your computer and use it in GitHub Desktop.

编译 gn 的时候遇到一些问题:

环境 win10 17763.1.amd64fre.rs5_release.180914-1434 + visual studio 2019 + vs dev cmd

  1. 含有 utf8 编码的字符,导致 C4819 警告,需要显示指定编码
  2. 找不到 last_commit_position.h 头文件, gen.py--out-path 参数需要传绝对路径
  3. 链接 fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64' 需要显示地设置 /MACHINE:x86
diff --git a/build/build_win.ninja.template b/build/build_win.ninja.template
index 3edfb6a4..0f8cb372 100644
--- a/build/build_win.ninja.template
+++ b/build/build_win.ninja.template
@@ -1,12 +1,12 @@
rule cc
- command = ninja -t msvc -- $cc /nologo /showIncludes /FC @${out}.rsp /c ${in} /Fo${out}
+ command = ninja -t msvc -- $cc /nologo /showIncludes /FC @${out}.rsp /c ${in} /Fo${out} /source-charset:utf-8 /execution-charset:utf-8
description = CC ${out}
rspfile = ${out}.rsp
rspfile_content = ${defines} ${includes} ${cflags} ${cflags_c}
deps = msvc
rule cxx
- command = ninja -t msvc -- $cxx /nologo /showIncludes /FC @${out}.rsp /c ${in} /Fo${out}
+ command = ninja -t msvc -- $cxx /nologo /showIncludes /FC @${out}.rsp /c ${in} /Fo${out} /source-charset:utf-8 /execution-charset:utf-8
description = CXX ${out}
rspfile = ${out}.rsp
rspfile_content = ${defines} ${includes} ${cflags} ${cflags_cc}
@@ -19,7 +19,7 @@ rule alink_thin
rspfile_content = ${in_newline} ${libflags}
rule link
- command = ninja -t msvc -- $ld /nologo /OUT:${out} /PDB:${out}.pdb @${out}.rsp
+ command = ninja -t msvc -- $ld /nologo /OUT:${out} /PDB:${out}.pdb @${out}.rsp /MACHINE:x86
description = LINK ${out}
rspfile = ${out}.rsp
rspfile_content = ${in_newline} ${libs} ${solibs} ${ldflags}
diff --git a/build/gen.py b/build/gen.py
index eeb7cb55..b473687c 100755
--- a/build/gen.py
+++ b/build/gen.py
@@ -274,7 +274,9 @@ def WriteGNNinja(path, platform, host, options):
cflags_cc = os.environ.get('CXXFLAGS', '').split()
ldflags = os.environ.get('LDFLAGS', '').split()
libflags = os.environ.get('LIBFLAGS', '').split()
+ #include_dirs = [REPO_ROOT, os.path.abspath(os.path.dirname(path))] or you can python gen.py --out-path=ABS_PATH
include_dirs = [REPO_ROOT, os.path.dirname(path)]
+
libs = []
if not platform.is_msvc():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment