Clang ++ --gcc-toolchain和gcc 4.9.3链接问题 [英] Clang++ --gcc-toolchain and gcc 4.9.3 linking issues

查看:531
本文介绍了Clang ++ --gcc-toolchain和gcc 4.9.3链接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(乌汶图16.04.1)

(Ubuntu 16.04.1)

默认情况下,在16.04.1上,clang为5.4选择gcc工具链.不幸的是,我有一个库,该库需要 5.0 ABI以下版本的,并且我无权访问源代码,也没有实施者发布新版本.我一直在尝试使用--gcc-toolchain选项,但无法使其正常工作. (ctrbegin.o和crtend.o在链接上没有正确的前缀.)

By default on 16.04.1 clang is picking the gcc tool chain for 5.4. Unfortunately I have a library that requires pre-5.0 ABI and I do NOT have access to the source, nor has the implementer released a new version. I've been trying to use the --gcc-toolchain option, but I can NOT get it to work. (ctrbegin.o and crtend.o don't get the proper prefix at link.)

$ clang++-3.8 -v -print-search-dirs

clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/5.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/6.0.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.0.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
programs: =/usr/bin:/usr/lib/llvm-3.8/bin:/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../x86_64-linux-gnu/bin

libraries: =/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu:
/lib/x86_64-linux-gnu:
/lib/../lib64:
/usr/lib/x86_64-linux-gnu:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../..:
/usr/lib/llvm-3.8/bin/../lib:
/lib:
/usr/lib

当我尝试指定--gcc-toolchain时,clang似乎接受了,然后完全忽略了该值. (与在16.04.1.上的clang ++-3.5发生相同的事情)

When I attempt to specify the --gcc-toolchain, clang seems to accept, then completely ignore the value. (Same thing happens with clang++-3.5 on 16.04.1.)

这是正确的语法吗?请注意,输出中缺少库目录.

Is this the proper syntax? Notice that the library directories are missing from the output.

$ clang++-3.8 -v --gcc-toolchain=/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.3 -print-search-dirs

clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
programs: =/usr/bin:/usr/lib/llvm-3.8/bin:/..//bin

libraries: =/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/llvm-3.8/bin/../lib:/lib:/usr/lib

我在上述主题上尝试了许多变体. (4.9,删除相对路径,等等.)我尝试了-isystem选项和-cxx-isystem选项. (两者都建议作为解决类似问题的方法.)

I have tried MANY variations on the above theme. (4.9, removing the relative path, etc.) I've tried the -isystem option and the -cxx-isystem option. (Both suggested as solutions to similar issues.)

我想念的是什么?(我希望这很简单,需要打一下头!)

What am i missing? (I hope it is simple and a head smack is in order!)

推荐答案

正如Gaetano在链接票证中所写的那样,您需要构建一个单独的目录,该目录可以作为--gcc-toolchain传递给clang.这是我稍微完善的代码.不需要bininclude链接.

As Gaetano wrote in the linked ticket, you need to build a separate directory that can be passed to clang as --gcc-toolchain. Here's my slightly refined code. No bin and include links are needed.

# The libstdc++ version you want to use
libstdcxx_version="4.9"
# Avoid calling arch twice
arch="$(arch)"
# The new toolchain root in the current directory
toolchain_root="$(pwd)/toolchain"
# The gcc library directory to be created
toolchain_gcc="$toolchain_root/lib/gcc/$arch-linux-gnu"
# Create that directory
mkdir -p "$toolchain_gcc"
# Find the longest matching libstdc++ version.
# Needed for clang-3.8 and older - they need 4.9.x rather than 4.9.
libstdcxx_dir=$(ls -d /usr/lib/gcc/$arch-linux-gnu/${libstdcxx_version}* \
  | tail -1)
# Link the libstdc++ library directory to the new location
ln -sfn "$libstdcxx_dir" "$toolchain_gcc/"
# Now you can add "--gcc-toolchain=$toolchain_root" to the clang flags

这篇关于Clang ++ --gcc-toolchain和gcc 4.9.3链接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆