1
+ <!DOCTYPE html>
2
+ < html lang ="zh-cmn-Hans ">
3
+ < head >
4
+ <!-- hexo-inject:begin --> <!-- hexo-inject:end --> < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Windows LLVM 环境的二三事 | Alpha</ title >
8
+
9
+
10
+ <!--link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/9.10.0/styles/github-gist.min.css"-->
11
+ < link rel ="stylesheet " href ="//cdn.jsdelivr.net/highlight.js/9.10.0/styles/github-gist.min.css ">
12
+ < link rel ="stylesheet " href ="/css/style.css "> <!-- hexo-inject:begin --> <!-- hexo-inject:end -->
13
+ </ head >
14
+
15
+ < body >
16
+ <!-- hexo-inject:begin --> <!-- hexo-inject:end --> < div class ="Shell ">
17
+ < aside class ='SideBar '>
18
+ < section class ='avatar '>
19
+ < div class ='av-pic '/>
20
+ </ section >
21
+ < section class ='menu '>
22
+ < div > nameoverflow</ div >
23
+ < div > What the f__k?</ div >
24
+ < ul >
25
+
26
+ < a href ="/ " class ="Btn ">
27
+ < li > Home</ li >
28
+ </ a >
29
+
30
+ < a href ="/archives/ " class ="Btn ">
31
+ < li > Archive</ li >
32
+ </ a >
33
+
34
+ < a href ="/tags/ " class ="Btn ">
35
+ < li > Tags</ li >
36
+ </ a >
37
+
38
+ < a href ="/about/ " class ="Btn ">
39
+ < li > About</ li >
40
+ </ a >
41
+
42
+ </ ul >
43
+ </ section >
44
+ < section class ="media ">
45
+
46
+
47
+ < a href ="https://github.com/nameoverflow ">
48
+ < img src ="/assets/github.svg " />
49
+ </ a >
50
+
51
+
52
+
53
+ < a href ="https://www.facebook.com/profile.php?id=100004252391322 ">
54
+ < img src ="/assets/facebook.svg " />
55
+ </ a >
56
+
57
+
58
+ </ section >
59
+ </ aside >
60
+
61
+ < div class ="container ">
62
+ < div data-pager-shell >
63
+ < div >
64
+ < article class ='ContentView '>
65
+ < header class ='PageTitle '>
66
+ < h1 > Windows LLVM 环境的二三事</ h1 >
67
+ </ header >
68
+
69
+ < section >
70
+ < p > 讲道理,考研党被这种配环境的事情打扰了咸鱼的生活是很不开心的。</ p >
71
+ < p > 起因是 Haskell 的 LLVM binding —— < code > llvm-general</ code > 在 Hackage 上只支持到 3.5 版本。当然 repo 里是有后续版本的,但是作者在 issues 里说后续的版本并没有弄好。</ p >
72
+ < p > 既然如此那就装 3.5 吧。然而下载了 LLVM 3.5.2 的源码后,Cmake 很顺利,用 VS 2017 打开也很顺利,然而编译的时候报错</ p >
73
+ < figure class ="highlight plain "> < table > < tr > < td class ="code "> < pre > < div class ="line "> 这里假装有编译 log (好吧忘记存了)</ div > </ pre > </ td > </ tr > </ table > </ figure >
74
+ < p > 总之就是某个类的方法后有 const 限定符,然后调用的上下文却又不是返回 const 于是不给过。</ p >
75
+ < p > 奇怪的是报错的位置是 VS 提供的标准库文件。这就很尴尬了。我要么改 VS 的标准库要么研究一波 LLVM 源码。</ p >
76
+ < p > 在 WSL 里试了一下,无痛编译。看来是 VS 有什么蛋疼的限制。网上稍微搜了一圈也没发现有类似情况(毕竟 3.5 的年代他们还没官方支持 VS 编译吧)。于是决定上 MinGW 来构建。</ p >
77
+ < p > 使用 CMake 生成 MinGW 的 makefile 并没有问题,然而在 make 的时候提示命令语法错误</ p >
78
+ < figure class ="highlight plain "> < table > < tr > < td class ="code "> < pre > < div class ="line "> 命令语法不正确。</ div > < div class ="line "> mingw32-make.exe[2]: *** [tools\lto\CMakeFiles\LTO_exports.dir\build.make:61: tools/lto/LTO.def] Error 1</ div > < div class ="line "> mingw32-make.exe[2]: *** Deleting file 'tools/lto/LTO.def'</ div > < div class ="line "> mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:9977: tools/lto/CMakeFiles/LTO_exports.dir/all] Error 2</ div > < div class ="line "> mingw32-make.exe: *** [Makefile:151: all] Error 2</ div > </ pre > </ td > </ tr > </ table > </ figure >
79
+ < p > 找到了这个 build.make 发现这一行的命令很奇怪</ p >
80
+ < figure class ="highlight powershell "> < table > < tr > < td class ="code "> < pre > < div class ="line "> cd /d C:\Users\hcyue\code\llvm-< span class ="number "> 3.5</ span > .< span class ="number "> 2</ span > .build\tools\lto && < span class ="string "> "C:\Program Files\CMake\bin\cmake.exe"</ span > -E echo EXPORTS > LTO.def</ div > < div class ="line "> cd /d C:\Users\hcyue\code\llvm-< span class ="number "> 3.5</ span > .< span class ="number "> 2</ span > .build\tools\lto && type C:/Users/hcyue/code/llvm-< span class ="number "> 3.5</ span > .< span class ="number "> 2</ span > .src/tools/lto/lto.exports >> LTO.def</ div > </ pre > </ td > </ tr > </ table > </ figure >
81
+ < p > 纵横 Windows 这么多年没见过 cd 还可以带个 < code > /d</ code > 参数的。那把它删了吧。</ p >
82
+ < p > 之后继续报错,link 的时候找不到 symbol。发现是刚刚改的那两行生成的目标文件 < code > LTO.def</ code > 有问题,不知道为什么没有写入成正常的文本文件,而是二进制文件(VS code 打开提示文件过大或为二进制文件)。直接 < code > type</ code > 出来是一个奇怪的、字距拉得很开的、看起来像是文本文件的格式。很气。</ p >
83
+ < p > 然而既然 < code > .def</ code > 反正是文本文件,我大不了手动构建一下 < code > def</ code > 。于是手动运行命令把 < code > lto.exports</ code > 里的东西 < code > type</ code > 出来</ p >
84
+ < figure class ="highlight powershell "> < table > < tr > < td class ="code "> < pre > < div class ="line "> type C:/Users/hcyue/code/llvm-< span class ="number "> 3.5</ span > .< span class ="number "> 2</ span > .src/tools/lto/lto.exports</ div > </ pre > </ td > </ tr > </ table > </ figure >
85
+ < p > 得到一大堆符号名</ p >
86
+ < figure class ="highlight plain "> < table > < tr > < td class ="code "> < pre > < div class ="line "> lto_get_error_message</ div > < div class ="line "> lto_get_version</ div > < div class ="line "> lto_initialize_disassembler</ div > < div class ="line "> lto_module_create</ div > < div class ="line "> lto_module_create_from_fd</ div > < div class ="line "> lto_module_create_from_fd_at_offset</ div > < div class ="line "> lto_module_create_from_memory</ div > < div class ="line "> </ div > < div class ="line "> (……一大堆 lto 符号名)</ div > < div class ="line "> </ div > < div class ="line "> LLVMCreateDisasm</ div > < div class ="line "> LLVMCreateDisasmCPU</ div > < div class ="line "> LLVMDisasmDispose</ div > < div class ="line "> LLVMDisasmInstruction</ div > < div class ="line "> LLVMSetDisasmOptions</ div > </ pre > </ td > </ tr > </ table > </ figure >
87
+ < p > 新建个 < code > LTO.def</ code > 把原来的覆盖掉,贴进去。</ p >
88
+ < p > 重新运行 < code > cmake --build .</ code > ,终于过了。</ p >
89
+
90
+
91
+
92
+
93
+ </ section >
94
+
95
+ < section class ='ArticleMeta '>
96
+ < div >
97
+ 发布于
98
+ < time datetime ="2017-04-08T17:44:05.000Z " itemprop ="datePublished ">
99
+ 2017-04-09
100
+ </ time >
101
+ </ div >
102
+
103
+ < div >
104
+ tags:
105
+ < li class ="meta-text ">
106
+ { < a href ="/tags/LLVM/ "> LLVM</ a > }
107
+ </ li >
108
+
109
+ < li class ="meta-text ">
110
+ { < a href ="/tags/compile/ "> compile</ a > }
111
+ </ li >
112
+
113
+
114
+ </ div >
115
+
116
+ </ section >
117
+
118
+ </ article >
119
+
120
+
121
+ </ div >
122
+
123
+ < footer >
124
+ < div > © 2016 - Hcyue</ div >
125
+ < div >
126
+ Powered by Hexo, all rights reserved
127
+ </ div >
128
+ </ footer >
129
+
130
+ </ div >
131
+ </ div >
132
+ </ div >
133
+ < script src ="/js/pager/dist/singlepager.js "> </ script >
134
+ < script >
135
+ var sp = new Pager ( 'data-pager-shell' )
136
+
137
+ </ script > <!-- hexo-inject:begin --> <!-- hexo-inject:end -->
138
+ </ body >
139
+ </ html >
0 commit comments