在Ubuntu 16.04上构建LLVM 6 Trunk不能构建lld [英] LLVM 6 Trunk Build on Ubuntu 16.04 not building lld
问题描述
我正在Ubuntu 16.04上构建LLVM 6.我也想要lld
.但是无论我做什么,lld
都不会构建/安装.
I am building LLVM 6 on Ubuntu 16.04. I want lld
too. But no matter what I do, lld
doesn't build/install.
遵循此处中的以下说明. 仍然在第一个和第二个中进行筛选:)
Followed the following instruction from here. Still sifting through first and second :)
-
阅读文档.
Read the documentation.
阅读文档.
请记住,您两次被警告阅读文档.
Remember that you were warned twice about reading the documentation.
特别是,指定的相对路径很重要.
In particular, the relative paths specified are important.
结帐LLVM:
cd where-you-want-llvm-to-live
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
结帐C语:
Checkout Clang:
cd where-you-want-llvm-to-live
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
结帐额外的Clang工具[可选]:
Checkout Extra Clang Tools [Optional]:
cd where-you-want-llvm-to-live
cd llvm/tools/clang/tools
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
结帐LLD链接器[可选]:
Checkout LLD linker [Optional]:
cd where-you-want-llvm-to-live
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/lld/trunk lld
没有下载其他可选软件包.由于svn
下载无法正常工作(svn: E000104: Error running context: Connection reset by peer
),因此我为 LLVM , C语, lld 从他们的github镜像中获取.从那时起,我就没有使用svn
来重命名文件夹(例如,将clang-tools-extra-master
更改为extra
).
Didn't download the other optional packages. Since svn
download was not working properly (svn: E000104: Error running context: Connection reset by peer
), I downloaded respective zip
for LLVM, Clang, clang-extra and lld from their github mirrors. Since, I didn't use svn
some renaming of the folders had to be done (for e.g. clang-tools-extra-master
to just extra
).
在cd
进入llvm
源文件夹的父文件夹后,执行以下操作
Then execute the following, after cd
ing into the parent folder of the llvm
source folder,
$ mkdir build; cd build
$ cmake ../llvm
$ make
等待+8小时后,我得到了除lld
之外的所有程序(clang
,lli
,llc
等).我希望它出现在文件夹build/bin
中.
After waiting for +8 hours, I get all the programs (clang
, lli
, llc
etc.) except lld
. I am expecting it to appear in the folder build/bin
.
我也尝试了选项cmake -DLLVM_ENABLE_PROJECTS=llvm/tools/lld ../llvm
. (-DLLVM_ENABLE_PROJECTS=lld
格式不起作用,我发现此讨论有关同一ENABLE问题.)
I have also tried the option cmake -DLLVM_ENABLE_PROJECTS=llvm/tools/lld ../llvm
. (The form -DLLVM_ENABLE_PROJECTS=lld
doesn't work and I found this place discussing about the same ENABLE issue.)
我已经尝试了三遍,进行了一些调整.由于需要花费大量时间进行编译,因此我决定寻求您的帮助.
I have already tried things with some tweaking three times. Since it takes so much time to compile, I decided to take your help.
一个单独的问题:在构建时,链接阶段需要在我的笔记本电脑上使用12 GB RAM + 8.8 GB交换空间! LLVM构建是否真的需要大于20 GB的内存? (我已经关闭了所有其他前台应用程序,尤其是firefox
)
A separate issue: While building, linking phase takes 12 GB RAM + 8.8 GB swap space on my laptop!! Does LLVM building really require >20 GB of ram ? (I had closed all other foreground apps, especially firefox
)
请让我知道是否需要更多信息.
Please let me know if any more information is needed.
推荐答案
首先,我认为LLVM_ENABLE_PROJECTS
选项在使用平面"源目录布局时很有用.就您而言,如果您按照编写的方式执行了结帐,那么它就没什么用了.
First of all, I think that the LLVM_ENABLE_PROJECTS
option is useful if you use a "flat" source directory layout. In your case, if you performed the checkouts as you wrote, then it's not of much use.
此外,@ PaulR关于使用ninja
的内容是一个很好的建议.重新启动生成时它更快且非常有用,并且可以根据nproc
并发生成尽可能多的单独的编译作业,而不必显式指定它.
Moreover, what @PaulR wrote about using ninja
is a very good suggestion. It's faster and very useful when restarting builds and it spawns as many separate compilation jobs concurrently as it can depending on the nproc
without having to specify it explicitly.
为加快构建速度并缩短链接时间,我还建议您使用BUILD_SHARED_LIBS
选项启用启用共享库的构建.
For faster build and shorter link times, I'd also suggest enabling a shared libs enabled build using the BUILD_SHARED_LIBS
option.
可以在此处,可以总结为:
- 使用
clang
构建clang
(自举或第二阶段构建). - 使用
gold
链接器代替ld
,以缩短链接时间. - 更喜欢生成共享库的版本.
- use
clang
to buildclang
(a bootstrapped or second-stage build). - use the
gold
linker insteadld
for faster linking times. - prefer a build producing shared libraries.
您现在可以跳过第1点(尽管您可以从系统软件包管理器中安装初始的llvm/clang
)
You can skip point 1 for now (although you could install an initial llvm/clang
from the system package manager)
最后,您可以使用LLVM_TARGETS_TO_BUILD
选项将编译限制为当前所需的特定目标后端.
Lastly, you could limit the compilation for the specific target backend you currently require using the LLVM_TARGETS_TO_BUILD
option.
我最近使用以下cmake
配置构建了trunk
(包括lld
):
I've built trunk
recently (including lld
) with this cmake
configuration:
CC=gcc CXX=g++ \
cmake -G Ninja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=On \
-DBUILD_SHARED_LIBS=On \
-DLLVM_ENABLE_ASSERTIONS=On \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_ENABLE_SPHINX=Off \
-DLLVM_ENABLE_THREADS=On \
-DLLVM_INSTALL_UTILS=On \
-DCMAKE_BUILD_TYPE=Debug \
[path-to-source-root-dir]
如果需要构建libcxx
,可以添加以下标志:
You can add the following flags if you need to build libcxx
:
[...]
-DLLVM_ENABLE_LIBCXX=On \
-DLIBCXX_ENABLE_EXCEPTIONS=On \
-DLIBCXX_ENABLE_RTTI=On \
[...]
对于使用另一个llvm/clang
和libc++
的自举构建,您可以将上述命令扩展为(在$PATH
环境变量中具有clang
):
For a bootstrapped build using another llvm/clang
and libc++
you can augment the above command as (having that clang
in your $PATH
environment variable):
LLVM_TOOLCHAIN_LIB_DIR=$(llvm-config --libdir)
LD_FLAGS=""
LD_FLAGS="${LD_FLAGS} -Wl,-L ${LLVM_TOOLCHAIN_LIB_DIR}"
LD_FLAGS="${LD_FLAGS} -Wl,-rpath-link ${LLVM_TOOLCHAIN_LIB_DIR}"
LD_FLAGS="${LD_FLAGS} -lc++ -lc++abi"
CXX_FLAGS=""
CXX_FLAGS="${CXX_FLAGS} -stdlib=libc++ -pthread"
CC=clang CXX=clang++ \
cmake -G Ninja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=On \
-DBUILD_SHARED_LIBS=On \
-DLLVM_ENABLE_LIBCXX=On \
-DLLVM_ENABLE_ASSERTIONS=On \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_ENABLE_SPHINX=Off \
-DLLVM_ENABLE_THREADS=On \
-DLLVM_INSTALL_UTILS=On \
-DLIBCXX_ENABLE_EXCEPTIONS=On \
-DLIBCXX_ENABLE_RTTI=On \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="${CXX_FLAGS}" \
-DCMAKE_SHARED_LINKER_FLAGS="${LD_FLAGS}" \
-DCMAKE_MODULE_LINKER_FLAGS="${LD_FLAGS}" \
-DCMAKE_EXE_LINKER_FLAGS="${LD_FLAGS}" \
-DCMAKE_POLICY_DEFAULT_CMP0056=NEW \
-DCMAKE_POLICY_DEFAULT_CMP0058=NEW \
[path-to-source-root-dir]
Moreover, another relevant SO question of interest can be found here.
正如您所写,阅读文档,再次尝试并阅读文档是解决问题的方法.
As you wrote, reading the documentation, experimenting and reading the documentation again is the way to go.
这篇关于在Ubuntu 16.04上构建LLVM 6 Trunk不能构建lld的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!