如何针对自定义 glibc 编译 LLVM?
How to compile LLVM against a custom glibc?
我正在使用 YouCompleteMe Vim plugin for text completion (installed through Vundle)。 YouCompleteMe 使用 Clang 为 C 系列语言(C、C++、Objective-C、Objective-C++)完成文本。然而,在 YouCompleteMe 更新后(通过 Vim 中的 :VundleUpdate
),YouCompleteMe 停止工作。
简而言之,问题是:如何针对自定义 glibc 版本编译 Clang? Debian Wheezy 附带 glibc 2.13,似乎最新的 Clang 版本至少需要glibc 2.15(下面有更详细的解释)。为了以防万一,我使用的是 Debian Wheezy、x86-64 和自定义 Linux 内核版本 4.0.0-rc6.
所以我按照LLVM website上的说明从git镜像下载了LLVM:
$ mkdir ~/code
$ cd ~/code/llvm_source_tree
$ git clone http://llvm.org/git/llvm.git
$ cd ~/code/llvm_source_tree/llvm/tools
$ git clone http://llvm.org/git/clang.git
$ cd ~/code/llvm_source_tree/llvm/projects
$ git clone http://llvm.org/git/compiler-rt.git
$ git clone http://llvm.org/git/test-suite.git
$ cd ~/code/llvm_source_tree/llvm
$ git config branch.master.rebase true
然后,我按照LLVM website上的说明编译了LLVM:
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
$ make -j 5
$ su
# make install
到目前为止一切正常,所以我通过编译 YouCompleteMe 支持库继续安装 YouCompleteMe YouCompleteMe install instructions:
$ mkdir ~/ycm_build
$ cd ~/ycm_build
$ cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
$ make ycm_support_libs
然后我 运行 Vim 我注意到 YouCompleteMe 似乎仍然无法正常工作。当我在某些 C++ 文件的 Vim 中进入编辑模式时(例如),YouCompleteMe 打印错误:The ycmd server SHUT DOWN (restart with :YcmRestartServer). Stderr (last 30 lines):
,然后 :YcmRestartServer
打印 Restarting ycmd server...
,然后 ('Connection aborted.', error(111, 'Connection refused'))
).
:YcmDebugInfo
打印以下内容:
Printing YouCompleteMe debug information...
-- Server crashed, no debug info from server
-- Server running at: http://127.0.0.1:37730
-- Server process ID: 22358
-- Server logfiles:
-- /tmp/ycm_temp/server_37730_stdout.log
-- /tmp/ycm_temp/server_37730_stderr.log
/tmp/ycm_temp/server_37730_stdout.log
为空,但 /tmp/ycm_temp/server_37730_stderr.log
包含以下行:
2015-05-20 17:06:46,126 - DEBUG - No global extra conf, not calling method YcmCorePreload
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/__main__.py", line 164, in
Main()
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/__main__.py", line 150, in Main
from ycmd import handlers
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/handlers.py", line 30, in
str( e ) ) )
RuntimeError: Error importing ycm_core. Are you sure you have placed a version 3.2+ libclang.[so|dll|dylib] in folder "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd"? See the Installation Guide in the docs. Full error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../libclang.so)
所以我 运行 测试了 YouCompleteMe 并在 运行ning ./vim/bundle/YouCompleteMe/third_party/ycmd/run_tests.sh
:
时得到了这个错误
[ 98%] Building CXX object ycm/tests/CMakeFiles/ycm_core_tests.dir/main.cpp.o
[100%] Building CXX object ycm/tests/CMakeFiles/ycm_core_tests.dir/TestUtils.cpp.o
Linking CXX executable ycm_core_tests
../../clang+llvm-3.6.0-x86_64-linux-gnu/lib/libclang.so: undefined reference to `posix_spawn@GLIBC_2.15'
../../clang+llvm-3.6.0-x86_64-linux-gnu/lib/libclang.so: undefined reference to `memcpy@GLIBC_2.14'
collect2: error: ld returned 1 exit status
make[3]: *** [ycm/tests/ycm_core_tests] Error 1
make[2]: *** [ycm/tests/CMakeFiles/ycm_core_tests.dir/all] Error 2
make[1]: *** [ycm/tests/CMakeFiles/ycm_core_tests.dir/rule] Error 2
make: *** [ycm_core_tests] Error 2
Traceback (most recent call last):
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 196, in
Main()
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 189, in Main
BuildYcmdLibs( GetCmakeArgs( args ) )
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 152, in BuildYcmdLibs
_err = sys.stderr )
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/sh/sh.py", line 1021, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/sh/sh.py", line 486, in __init__
self.wait()
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/sh/sh.py", line 500, in wait
self.handle_command_exit_code(exit_code)
File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/sh/sh.py", line 516, in handle_command_exit_code
raise exc(self.ran, self.process.stdout, self.process.stderr)
sh.ErrorReturnCode_2:
RAN: '/usr/bin/make -j 8 ycm_core_tests'
STDOUT:
STDERR:
看来 Clang 3.6.0 可能需要 glibc 2.15 或更新版本。 Debian Wheezy 附带 glibc 2.13。所以决定安装最新的稳定版glibc(目前是2.21)。我之前已经编译了 binutils 并将其安装到 /usr/local/bin/
,所以我现在不需要这样做。
所以我下载了http://ftp.gnu.org/gnu/glibc/glibc-2.21.tar.bz2然后解压编译源码安装:
$ cd ~/code
$ mkdir ~/code/glibc
$ cd ~/code/glibc
$ mv -iv ~/downloads/glibc-2.21.tar.bz2 .
$ tar xjvf glibc-2.21.tar.bz2
$ cd glibc-2.21
$ mkdir build
$ cd build
$ ../configure --with-binutils=/usr/local/bin --prefix=/usr/local/glibc/glibc-2.21
$ make -j 5
$ su
# make install
然后我重新编译了LLVM。在 Employed Russian 对 SO 问题 Multiple glibc libraries on a single host:
的回答之后,我将 CMAKE_CXX_FLAGS
环境变量 g++ 链接器标志传递给 cmake
$ export CMAKE_CXX_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux.so.2'
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
$ make -j 5
然后我重新编译了 YouCompleteMe 支持库,再次将 g++ 链接器标志传递给 cmake
in CMAKE_CXX_FLAGS
:
$ export CMAKE_CXX_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux.so.2'
$ cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
但是 YouCompleteMe 的问题仍然存在,测试仍然以同样的方式失败。也许 CMAKE_CXX_FLAGS
不足以将 g++ 链接器标志传递给 cmake
?在针对 glibc 2.21 编译 LLVM 时,我还尝试使用 LD_LIBRARY_PATH
:
$ cd ~/code/llvm_source_tree
$ mkdir build2
$ cd build2
$ export LD_LIBRARY_PATH="/usr/local/glibc/glibc-2.21/lib:$LD_LIBRARY_PATH"
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
并得到这个错误:
cmake: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument
那我也试了LD_PRELOAD
:
$ export LD_PRELOAD='/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2 /usr/local/glibc/glibc-2.21/lib/libc.so.6'
$ export LD_LIBRARY_PATH="/usr/local/glibc/glibc-2.21/lib:$LD_LIBRARY_PATH"
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
并得到这些错误:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
Inconsistency detected by ld.so: dl-minimal.c: 136: realloc: Assertion `ptr == alloc_last_block' failed!
然后我也尝试将/usr/local/glibc/glibc-2.21/lib/ld-2.21.so
添加到export LD_PRELOAD
,但它并没有以任何方式改变错误信息。
我很确定 Clang 不需要 glibc 2.15(准确),即使另一个缺失的符号(posix_spawn@GLIBC_2.15
)最初来自 glibc 2.15,因为 glibc 根据其文档试图保持向后兼容性无论如何,另一个缺失的符号 (memcpy@GLIBC_2.14
) 来自 glibc 2.14。所以我没有用 glibc 2.15 尝试这一切。但现在我没有想法,任何建议将不胜感激。
编辑 1
我遵循 , but my problem did not change in any way. So I concluded that export CMAKE_CXX_FLAGS
is not the right way to pass g++ linker flags to cmake
. CMAKE_CXX_FLAGS
is the name of an variable internal to cmake
, but cmake
does not care at all about an environment variable with the same name (CMAKE_CXX_FLAGS
). CMAKE_CXX_FLAGS
can be defined directly in CMakeLists.txt
, but in LLVM compiling instructions 没有使用 master CMakeLists.txt
并且如果有一些更实用的选项,我不想从头开始重新创建 LLVM 编译脚本。但是我仍然可以找到 3 个其他选项:
cmake
从名为 CXXFLAGS
的环境变量初始化 CMAKE_CXX_FLAGS
。请参阅 sakra 对 SO 问题的回答 Adding include directories to cmake when calling it from command line。
$ export CXXFLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux-x86-64.so.2'
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
$ make
CMAKE_CXX_FLAGS
也可以使用 -DCMAKE_CXX_FLAGS
: 从命令行初始化
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' -DCMAKE_CXX_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux-x86-64.so.2' ~/code/llvm_source_tree/llvm/
$ make
CMAKE_CXX_FLAGS
也可以使用 -DCMAKE_CXX_FLAGS:STRING
从命令行初始化(参见 Building mpllibs):
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' -DCMAKE_CXX_FLAGS:STRING='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux-x86-64.so.2' ~/code/llvm_source_tree/llvm/
$ make
所有这 3 个选项都产生完全相同的结果:编译 LLVM 以与目标 llvm-tblgen
和 intrinsics_gen
相关的相同错误结束(3 [=50= 之间的唯一区别]上面由cmake
命令生成的在目录名中,这是由于每个构建都是在不同的目录中完成的)。似乎目标 llvm-tblgen
得到了适当的编译和链接,但在那之后目标 llvm-tblgen
似乎是目标 intrinsics_gen
的依赖项,并且不知何故无法找到 llvm-tblgen
.这些是 make
输出的最后几行(这些对于上面的 3 个构建中的每一个都是相同的):
Linking CXX executable ../../bin/llvm-tblgen
[ 4%] Built target llvm-tblgen
Scanning dependencies of target intrinsics_gen
[ 4%] Building Intrinsics.gen...
/bin/sh: 1: ../../../bin/llvm-tblgen: not found
make[2]: *** [include/llvm/IR/Intrinsics.gen.tmp] Error 127
make[1]: *** [include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all] Error 2
make: *** [all] Error 2
我想知道这是否是 LLVM 中的错误,或者是否按照我的方式(在上面的 3 个构建中)设置 cmake
变量 CMAKE_CXX_FLAGS
是否足够,或者这是由其他原因引起的。任何关于如何继续的想法将不胜感激。
编辑 2
正如 Employed Russian 在他的评论 () 中所建议的那样:
$ export CXXFLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2'
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
$ make
这也导致了与目标 llvm-tblgen
和 intrinsics_gen
相关的编译错误,但该错误与之前的错误不同。这些是 make
输出的最后几行:
Linking CXX executable ../../bin/llvm-tblgen
[ 4%] Built target llvm-tblgen
Scanning dependencies of target intrinsics_gen
[ 4%] Building Intrinsics.gen...
../../../bin/llvm-tblgen: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
make[2]: *** [include/llvm/IR/Intrinsics.gen.tmp] Error 127
make[1]: *** [include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all] Error 2
make: *** [all] Error 2
所以现在似乎找到了 llvm-tblgen
,但是加载共享库 libtinfo.so.5
时出错。所以我把--rpath=/usr/local/glibc/glibc-2.21
改成--rpath=/usr/local/glibc/glibc-2.21/lib
再试:
$ export CXXFLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21/lib -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2'
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
$ make
然而,--rpath
的这一变化根本没有改变 make
产生的错误信息。我想知道这个共享库 libtinfo.so.5
应该放在哪里。
然后我遇到了Building the Clang + LLVM compilers website并尝试将-std=c++11
添加到CXXFLAGS
:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2'
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
$ make
但是没有用,错误信息是一样的,就是共享库libtinfo.so.5
还是找不到。也许我的 g++
版本太旧了,它是 Debian Wheezy 附带的 g++
4.7.2(g++ --version
打印 g++ (Debian 4.7.2-5) 4.7.2
)。 Building the Clang + LLVM compilers website 的作者写道,他试图仅使用 g++
4.7.1 在 Fedora 15 上构建 LLVM 失败,而使用不同的 g++
版本(4.8、4.8.0)多次重新启动编译它, 4.7.1) 终于成功了(网站上有描述)。有什么想法吗?
编辑 3
根据 Employed Russian 的建议,我用 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu
:
重新编译了 glibc 2.21
$ cd ~/code/glibc/glibc-2.21
$ mv -iv build old_build
$ mkdir build
$ cd build
$ export LD_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu'
$ ../configure --with-binutils=/usr/local/bin --prefix=/usr/local/glibc/glibc-2.21
$ make -j 5
make check
产生了一些错误:
Summary of test results:
112 FAIL
2073 PASS
199 XFAIL
3 XPASS
make[1]: *** [tests] Error 1
make[1]: Leaving directory `/home/user/code/glibc/glibc-2.21'
make: *** [check] Error 2
反正我安装了新编译的glibc 2.21:
$ su
# make install
make install
产生了这个警告:
/home/user/code/glibc/glibc-2.21/build/elf/ldconfig: Warning: ignoring configuration file that cannot be opened: /usr/local/glibc/glibc-2.21/etc/ld.so.conf: No such file or directory
make[1]: Leaving directory `/home/user/code/glibc/glibc-2.21'
然后我再次重新编译 LLVM:-Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu
:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2'
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
$ make
但是 libstdc++.so.6
不见了:
Linking CXX executable ../../bin/llvm-tblgen
[ 4%] Built target llvm-tblgen
Scanning dependencies of target intrinsics_gen
[ 4%] Building Intrinsics.gen...
../../../bin/llvm-tblgen: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
make[2]: *** [include/llvm/IR/Intrinsics.gen.tmp] Error 127
make[1]: *** [include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all] Error 2
make: *** [all] Error 2
所以我得出结论,--rpath
.
肯定还需要一些其他的库目录
$ cd /usr
$ sudo find . -name 'libstdc++.so.6'
./lib32/debug/libstdc++.so.6
./lib32/libstdc++.so.6
./lib/x86_64-linux-gnu/debug/libstdc++.so.6
./lib/x86_64-linux-gnu/libstdc++.so.6
./lib/git-annex.linux/usr/lib/x86_64-linux-gnu/libstdc++.so.6
./lib/i386-linux-gnu/libstdc++.so.6
其中,./lib/x86_64-linux-gnu/libstdc++.so.6
看起来最适合我。所以我将/usr/lib/x86_64-linux-gnu
添加到--rpath
,并再次重新编译glibc 2.21:
$ cd ~/code/glibc/glibc-2.21
$ mv -iv build old_build2
$ mkdir build
$ cd build
$ export LD_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu'
$ ../configure --with-binutils=/usr/local/bin --prefix=/usr/local/glibc/glibc-2.21
$ make -j 5
这次我没有费心make check
,而是直接继续安装:
$ su
# make install
并得到同样看似无害的警告:
/home/user/code/glibc/glibc-2.21/build/elf/ldconfig: Warning: ignoring configuration file that cannot be opened: /usr/local/glibc/glibc-2.21/etc/ld.so.conf: No such file or directory
make[1]: Leaving directory `/home/user/code/glibc/glibc-2.21'
所以我为 LLVM 添加了 /usr/lib/x86_64-linux-gnu
到 --rpath
,并重新编译了 LLVM:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2'
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
$ make
构建成功,所以我安装了LLVM:
$ su
# make install
然后我重新编译了 YouCompleteMe 支持库,CXXFLAGS
我用于编译 LLVM:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2'
$ cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
$ make ycm_support_libs
这个构建也成功了。然后我重新安装了 YouCompleteMe:
$ cd
$ .vim/bundle/YouCompleteMe/install.sh
完成似乎有效。然后我运行 YouCompleteMe的测试:
$ .vim/bundle/YouCompleteMe/run_tests.sh
好的,完成仍然有效。
$ .vim/bundle/YouCompleteMe/third_party/ycmd/run_tests.sh
这导致了一个问题。似乎这个 .vim/bundle/YouCompleteMe/third_party/ycmd/run_tests.sh
重新编译了支持库 - 没有使用我的 Makefile
- 因此破坏了支持库。解决方案是 而不是 到 运行 .vim/bundle/YouCompleteMe/third_party/ycmd/run_tests.sh
.
[100%] Building CXX object ycm/tests/CMakeFiles/ycm_core_tests.dir/TestUtils.cpp.o
Linking CXX executable ycm_core_tests
../../clang+llvm-3.6.0-x86_64-linux-gnu/lib/libclang.so: undefined reference to `posix_spawn@GLIBC_2.15'
../../clang+llvm-3.6.0-x86_64-linux-gnu/lib/libclang.so: undefined reference to `memcpy@GLIBC_2.14'
collect2: error: ld returned 1 exit status
make[3]: *** [ycm/tests/ycm_core_tests] Error 1
make[2]: *** [ycm/tests/CMakeFiles/ycm_core_tests.dir/all] Error 2
make[1]: *** [ycm/tests/CMakeFiles/ycm_core_tests.dir/rule] Error 2
make: *** [ycm_core_tests] Error 2
所以我重新编译了支持库,就像我最近做的那样,之后又重新安装了 YouCompleteMe:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2'
$ cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
$ make ycm_support_libs
$ cd
$ .vim/bundle/YouCompleteMe/install.sh
最后,YouCompleteMe 再次工作!
Then I also tried LD_PRELOAD
如 here 所述,为了使用自定义 glibc,您需要设置正确的 --dynamic-linker
。
我看到您正在使用 --dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux.so.2
,但这看起来不对:您需要 ld-linux-x86-64.so.2
。
export LD_PRELOAD='/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2 ...
那个(ld-linux
的预加载) 永远不会 起作用:首先解释 LD_PRELOAD
的是 ld-linux
。
我正在使用 YouCompleteMe Vim plugin for text completion (installed through Vundle)。 YouCompleteMe 使用 Clang 为 C 系列语言(C、C++、Objective-C、Objective-C++)完成文本。然而,在 YouCompleteMe 更新后(通过 Vim 中的 :VundleUpdate
),YouCompleteMe 停止工作。
简而言之,问题是:如何针对自定义 glibc 版本编译 Clang? Debian Wheezy 附带 glibc 2.13,似乎最新的 Clang 版本至少需要glibc 2.15(下面有更详细的解释)。为了以防万一,我使用的是 Debian Wheezy、x86-64 和自定义 Linux 内核版本 4.0.0-rc6.
所以我按照LLVM website上的说明从git镜像下载了LLVM:
$ mkdir ~/code $ cd ~/code/llvm_source_tree $ git clone http://llvm.org/git/llvm.git $ cd ~/code/llvm_source_tree/llvm/tools $ git clone http://llvm.org/git/clang.git $ cd ~/code/llvm_source_tree/llvm/projects $ git clone http://llvm.org/git/compiler-rt.git $ git clone http://llvm.org/git/test-suite.git $ cd ~/code/llvm_source_tree/llvm $ git config branch.master.rebase true
然后,我按照LLVM website上的说明编译了LLVM:
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/ $ make -j 5 $ su # make install
到目前为止一切正常,所以我通过编译 YouCompleteMe 支持库继续安装 YouCompleteMe YouCompleteMe install instructions:
$ mkdir ~/ycm_build $ cd ~/ycm_build $ cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp $ make ycm_support_libs
然后我 运行 Vim 我注意到 YouCompleteMe 似乎仍然无法正常工作。当我在某些 C++ 文件的 Vim 中进入编辑模式时(例如),YouCompleteMe 打印错误:The ycmd server SHUT DOWN (restart with :YcmRestartServer). Stderr (last 30 lines):
,然后 :YcmRestartServer
打印 Restarting ycmd server...
,然后 ('Connection aborted.', error(111, 'Connection refused'))
).
:YcmDebugInfo
打印以下内容:
Printing YouCompleteMe debug information... -- Server crashed, no debug info from server -- Server running at: http://127.0.0.1:37730 -- Server process ID: 22358 -- Server logfiles: -- /tmp/ycm_temp/server_37730_stdout.log -- /tmp/ycm_temp/server_37730_stderr.log
/tmp/ycm_temp/server_37730_stdout.log
为空,但 /tmp/ycm_temp/server_37730_stderr.log
包含以下行:
2015-05-20 17:06:46,126 - DEBUG - No global extra conf, not calling method YcmCorePreload Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/__main__.py", line 164, in Main() File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/__main__.py", line 150, in Main from ycmd import handlers File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/handlers.py", line 30, in str( e ) ) ) RuntimeError: Error importing ycm_core. Are you sure you have placed a version 3.2+ libclang.[so|dll|dylib] in folder "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd"? See the Installation Guide in the docs. Full error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../libclang.so)
所以我 运行 测试了 YouCompleteMe 并在 运行ning ./vim/bundle/YouCompleteMe/third_party/ycmd/run_tests.sh
:
[ 98%] Building CXX object ycm/tests/CMakeFiles/ycm_core_tests.dir/main.cpp.o [100%] Building CXX object ycm/tests/CMakeFiles/ycm_core_tests.dir/TestUtils.cpp.o Linking CXX executable ycm_core_tests ../../clang+llvm-3.6.0-x86_64-linux-gnu/lib/libclang.so: undefined reference to `posix_spawn@GLIBC_2.15' ../../clang+llvm-3.6.0-x86_64-linux-gnu/lib/libclang.so: undefined reference to `memcpy@GLIBC_2.14' collect2: error: ld returned 1 exit status make[3]: *** [ycm/tests/ycm_core_tests] Error 1 make[2]: *** [ycm/tests/CMakeFiles/ycm_core_tests.dir/all] Error 2 make[1]: *** [ycm/tests/CMakeFiles/ycm_core_tests.dir/rule] Error 2 make: *** [ycm_core_tests] Error 2 Traceback (most recent call last): File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 196, in Main() File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 189, in Main BuildYcmdLibs( GetCmakeArgs( args ) ) File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 152, in BuildYcmdLibs _err = sys.stderr ) File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/sh/sh.py", line 1021, in __call__ return RunningCommand(cmd, call_args, stdin, stdout, stderr) File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/sh/sh.py", line 486, in __init__ self.wait() File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/sh/sh.py", line 500, in wait self.handle_command_exit_code(exit_code) File "/home/user/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/sh/sh.py", line 516, in handle_command_exit_code raise exc(self.ran, self.process.stdout, self.process.stderr) sh.ErrorReturnCode_2: RAN: '/usr/bin/make -j 8 ycm_core_tests' STDOUT: STDERR:
看来 Clang 3.6.0 可能需要 glibc 2.15 或更新版本。 Debian Wheezy 附带 glibc 2.13。所以决定安装最新的稳定版glibc(目前是2.21)。我之前已经编译了 binutils 并将其安装到 /usr/local/bin/
,所以我现在不需要这样做。
所以我下载了http://ftp.gnu.org/gnu/glibc/glibc-2.21.tar.bz2然后解压编译源码安装:
$ cd ~/code $ mkdir ~/code/glibc $ cd ~/code/glibc $ mv -iv ~/downloads/glibc-2.21.tar.bz2 . $ tar xjvf glibc-2.21.tar.bz2 $ cd glibc-2.21 $ mkdir build $ cd build $ ../configure --with-binutils=/usr/local/bin --prefix=/usr/local/glibc/glibc-2.21 $ make -j 5 $ su # make install
然后我重新编译了LLVM。在 Employed Russian 对 SO 问题 Multiple glibc libraries on a single host:
的回答之后,我将CMAKE_CXX_FLAGS
环境变量 g++ 链接器标志传递给 cmake
$ export CMAKE_CXX_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux.so.2' $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/ $ make -j 5
然后我重新编译了 YouCompleteMe 支持库,再次将 g++ 链接器标志传递给 cmake
in CMAKE_CXX_FLAGS
:
$ export CMAKE_CXX_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux.so.2' $ cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
但是 YouCompleteMe 的问题仍然存在,测试仍然以同样的方式失败。也许 CMAKE_CXX_FLAGS
不足以将 g++ 链接器标志传递给 cmake
?在针对 glibc 2.21 编译 LLVM 时,我还尝试使用 LD_LIBRARY_PATH
:
$ cd ~/code/llvm_source_tree $ mkdir build2 $ cd build2 $ export LD_LIBRARY_PATH="/usr/local/glibc/glibc-2.21/lib:$LD_LIBRARY_PATH" $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
并得到这个错误:
cmake: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument
那我也试了LD_PRELOAD
:
$ export LD_PRELOAD='/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2 /usr/local/glibc/glibc-2.21/lib/libc.so.6' $ export LD_LIBRARY_PATH="/usr/local/glibc/glibc-2.21/lib:$LD_LIBRARY_PATH" $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/
并得到这些错误:
-- The C compiler identification is unknown -- The CXX compiler identification is unknown Inconsistency detected by ld.so: dl-minimal.c: 136: realloc: Assertion `ptr == alloc_last_block' failed!
然后我也尝试将/usr/local/glibc/glibc-2.21/lib/ld-2.21.so
添加到export LD_PRELOAD
,但它并没有以任何方式改变错误信息。
我很确定 Clang 不需要 glibc 2.15(准确),即使另一个缺失的符号(posix_spawn@GLIBC_2.15
)最初来自 glibc 2.15,因为 glibc 根据其文档试图保持向后兼容性无论如何,另一个缺失的符号 (memcpy@GLIBC_2.14
) 来自 glibc 2.14。所以我没有用 glibc 2.15 尝试这一切。但现在我没有想法,任何建议将不胜感激。
编辑 1
我遵循 export CMAKE_CXX_FLAGS
is not the right way to pass g++ linker flags to cmake
. CMAKE_CXX_FLAGS
is the name of an variable internal to cmake
, but cmake
does not care at all about an environment variable with the same name (CMAKE_CXX_FLAGS
). CMAKE_CXX_FLAGS
can be defined directly in CMakeLists.txt
, but in LLVM compiling instructions 没有使用 master CMakeLists.txt
并且如果有一些更实用的选项,我不想从头开始重新创建 LLVM 编译脚本。但是我仍然可以找到 3 个其他选项:
cmake
从名为CXXFLAGS
的环境变量初始化CMAKE_CXX_FLAGS
。请参阅 sakra 对 SO 问题的回答 Adding include directories to cmake when calling it from command line。
$ export CXXFLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux-x86-64.so.2' $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/ $ make
CMAKE_CXX_FLAGS
也可以使用-DCMAKE_CXX_FLAGS
: 从命令行初始化
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' -DCMAKE_CXX_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux-x86-64.so.2' ~/code/llvm_source_tree/llvm/ $ make
CMAKE_CXX_FLAGS
也可以使用-DCMAKE_CXX_FLAGS:STRING
从命令行初始化(参见 Building mpllibs):
$ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' -DCMAKE_CXX_FLAGS:STRING='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux-x86-64.so.2' ~/code/llvm_source_tree/llvm/ $ make
所有这 3 个选项都产生完全相同的结果:编译 LLVM 以与目标 llvm-tblgen
和 intrinsics_gen
相关的相同错误结束(3 [=50= 之间的唯一区别]上面由cmake
命令生成的在目录名中,这是由于每个构建都是在不同的目录中完成的)。似乎目标 llvm-tblgen
得到了适当的编译和链接,但在那之后目标 llvm-tblgen
似乎是目标 intrinsics_gen
的依赖项,并且不知何故无法找到 llvm-tblgen
.这些是 make
输出的最后几行(这些对于上面的 3 个构建中的每一个都是相同的):
Linking CXX executable ../../bin/llvm-tblgen [ 4%] Built target llvm-tblgen Scanning dependencies of target intrinsics_gen [ 4%] Building Intrinsics.gen... /bin/sh: 1: ../../../bin/llvm-tblgen: not found make[2]: *** [include/llvm/IR/Intrinsics.gen.tmp] Error 127 make[1]: *** [include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all] Error 2 make: *** [all] Error 2
我想知道这是否是 LLVM 中的错误,或者是否按照我的方式(在上面的 3 个构建中)设置 cmake
变量 CMAKE_CXX_FLAGS
是否足够,或者这是由其他原因引起的。任何关于如何继续的想法将不胜感激。
编辑 2
正如 Employed Russian 在他的评论 (
$ export CXXFLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2' $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/ $ make
这也导致了与目标 llvm-tblgen
和 intrinsics_gen
相关的编译错误,但该错误与之前的错误不同。这些是 make
输出的最后几行:
Linking CXX executable ../../bin/llvm-tblgen [ 4%] Built target llvm-tblgen Scanning dependencies of target intrinsics_gen [ 4%] Building Intrinsics.gen... ../../../bin/llvm-tblgen: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory make[2]: *** [include/llvm/IR/Intrinsics.gen.tmp] Error 127 make[1]: *** [include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all] Error 2 make: *** [all] Error 2
所以现在似乎找到了 llvm-tblgen
,但是加载共享库 libtinfo.so.5
时出错。所以我把--rpath=/usr/local/glibc/glibc-2.21
改成--rpath=/usr/local/glibc/glibc-2.21/lib
再试:
$ export CXXFLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21/lib -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2' $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/ $ make
然而,--rpath
的这一变化根本没有改变 make
产生的错误信息。我想知道这个共享库 libtinfo.so.5
应该放在哪里。
然后我遇到了Building the Clang + LLVM compilers website并尝试将-std=c++11
添加到CXXFLAGS
:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21 -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2' $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/ $ make
但是没有用,错误信息是一样的,就是共享库libtinfo.so.5
还是找不到。也许我的 g++
版本太旧了,它是 Debian Wheezy 附带的 g++
4.7.2(g++ --version
打印 g++ (Debian 4.7.2-5) 4.7.2
)。 Building the Clang + LLVM compilers website 的作者写道,他试图仅使用 g++
4.7.1 在 Fedora 15 上构建 LLVM 失败,而使用不同的 g++
版本(4.8、4.8.0)多次重新启动编译它, 4.7.1) 终于成功了(网站上有描述)。有什么想法吗?
编辑 3
根据 Employed Russian 的建议,我用 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu
:
$ cd ~/code/glibc/glibc-2.21 $ mv -iv build old_build $ mkdir build $ cd build $ export LD_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu' $ ../configure --with-binutils=/usr/local/bin --prefix=/usr/local/glibc/glibc-2.21 $ make -j 5
make check
产生了一些错误:
Summary of test results: 112 FAIL 2073 PASS 199 XFAIL 3 XPASS make[1]: *** [tests] Error 1 make[1]: Leaving directory `/home/user/code/glibc/glibc-2.21' make: *** [check] Error 2
反正我安装了新编译的glibc 2.21:
$ su # make install
make install
产生了这个警告:
/home/user/code/glibc/glibc-2.21/build/elf/ldconfig: Warning: ignoring configuration file that cannot be opened: /usr/local/glibc/glibc-2.21/etc/ld.so.conf: No such file or directory make[1]: Leaving directory `/home/user/code/glibc/glibc-2.21'
然后我再次重新编译 LLVM:-Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu
:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2' $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/ $ make
但是 libstdc++.so.6
不见了:
Linking CXX executable ../../bin/llvm-tblgen [ 4%] Built target llvm-tblgen Scanning dependencies of target intrinsics_gen [ 4%] Building Intrinsics.gen... ../../../bin/llvm-tblgen: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory make[2]: *** [include/llvm/IR/Intrinsics.gen.tmp] Error 127 make[1]: *** [include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all] Error 2 make: *** [all] Error 2
所以我得出结论,--rpath
.
$ cd /usr $ sudo find . -name 'libstdc++.so.6' ./lib32/debug/libstdc++.so.6 ./lib32/libstdc++.so.6 ./lib/x86_64-linux-gnu/debug/libstdc++.so.6 ./lib/x86_64-linux-gnu/libstdc++.so.6 ./lib/git-annex.linux/usr/lib/x86_64-linux-gnu/libstdc++.so.6 ./lib/i386-linux-gnu/libstdc++.so.6
其中,./lib/x86_64-linux-gnu/libstdc++.so.6
看起来最适合我。所以我将/usr/lib/x86_64-linux-gnu
添加到--rpath
,并再次重新编译glibc 2.21:
$ cd ~/code/glibc/glibc-2.21 $ mv -iv build old_build2 $ mkdir build $ cd build $ export LD_FLAGS='-Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu' $ ../configure --with-binutils=/usr/local/bin --prefix=/usr/local/glibc/glibc-2.21 $ make -j 5
这次我没有费心make check
,而是直接继续安装:
$ su # make install
并得到同样看似无害的警告:
/home/user/code/glibc/glibc-2.21/build/elf/ldconfig: Warning: ignoring configuration file that cannot be opened: /usr/local/glibc/glibc-2.21/etc/ld.so.conf: No such file or directory make[1]: Leaving directory `/home/user/code/glibc/glibc-2.21'
所以我为 LLVM 添加了 /usr/lib/x86_64-linux-gnu
到 --rpath
,并重新编译了 LLVM:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2' $ cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE='Release' ~/code/llvm_source_tree/llvm/ $ make
构建成功,所以我安装了LLVM:
$ su # make install
然后我重新编译了 YouCompleteMe 支持库,CXXFLAGS
我用于编译 LLVM:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2' $ cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp $ make ycm_support_libs
这个构建也成功了。然后我重新安装了 YouCompleteMe:
$ cd $ .vim/bundle/YouCompleteMe/install.sh
完成似乎有效。然后我运行 YouCompleteMe的测试:
$ .vim/bundle/YouCompleteMe/run_tests.sh
好的,完成仍然有效。
$ .vim/bundle/YouCompleteMe/third_party/ycmd/run_tests.sh
这导致了一个问题。似乎这个 .vim/bundle/YouCompleteMe/third_party/ycmd/run_tests.sh
重新编译了支持库 - 没有使用我的 Makefile
- 因此破坏了支持库。解决方案是 而不是 到 运行 .vim/bundle/YouCompleteMe/third_party/ycmd/run_tests.sh
.
[100%] Building CXX object ycm/tests/CMakeFiles/ycm_core_tests.dir/TestUtils.cpp.o Linking CXX executable ycm_core_tests ../../clang+llvm-3.6.0-x86_64-linux-gnu/lib/libclang.so: undefined reference to `posix_spawn@GLIBC_2.15' ../../clang+llvm-3.6.0-x86_64-linux-gnu/lib/libclang.so: undefined reference to `memcpy@GLIBC_2.14' collect2: error: ld returned 1 exit status make[3]: *** [ycm/tests/ycm_core_tests] Error 1 make[2]: *** [ycm/tests/CMakeFiles/ycm_core_tests.dir/all] Error 2 make[1]: *** [ycm/tests/CMakeFiles/ycm_core_tests.dir/rule] Error 2 make: *** [ycm_core_tests] Error 2
所以我重新编译了支持库,就像我最近做的那样,之后又重新安装了 YouCompleteMe:
$ export CXXFLAGS='-std=c++11 -Wl,--rpath=/usr/local/glibc/glibc-2.21/lib:/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu -Wl,--dynamic-linker=/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2' $ cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp $ make ycm_support_libs
$ cd $ .vim/bundle/YouCompleteMe/install.sh
最后,YouCompleteMe 再次工作!
Then I also tried LD_PRELOAD
如 here 所述,为了使用自定义 glibc,您需要设置正确的 --dynamic-linker
。
我看到您正在使用 --dynamic-linker=/usr/local/glibc/glibc-2.21/ld-linux.so.2
,但这看起来不对:您需要 ld-linux-x86-64.so.2
。
export LD_PRELOAD='/usr/local/glibc/glibc-2.21/lib/ld-linux-x86-64.so.2 ...
那个(ld-linux
的预加载) 永远不会 起作用:首先解释 LD_PRELOAD
的是 ld-linux
。