Fedora 21与铛,没有gcc [英] Fedora 21 with clang, without gcc

查看:489
本文介绍了Fedora 21与铛,没有gcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以(合理地)使Fedora 21到只有llvm / clang / libc ++ / libc ++ abi的地方吗? (我发现一些事情暗示没有,但他们都是约3岁,并且llvm /铛自那以后已经走了很长的路。)



我尝试了

  yum install gcc gcc-c ++ 
(下载,构建,安装了llvm / cfe -rt / libcxx / libcxxabi from svn)
yum remove gcc gcc-c ++
添加到/ etc / profile:export CC = / usr / local / bin / clang \ export CXX = / usr / local / bin / clang ++
(在硬布线情况下)
ln -s / usr / local / bin / clang / usr / local / bin / gcc
ln -s / usr / local / bin / clang / usr / local / bin / cc
ln -s / usr / local / bin / clang ++ / usr / local / bin / g ++
ln -s / usr / usr / local / bin / c ++
ldconfig

我很高兴,我得到了:

  ld:找不到crtbegin.o 
ld:找不到-lgcc
ld:找不到-lgcc_s

clang -v include

 找到候选GCC安装:/usr/lib/gcc/x86_64-redhat-linux/4.9.2 

ldconfig&& ldconfig -p | grep libgcc does show

  libgcc_s.so.1(libc6,x86-64)=> /lib64/libgcc_s.so.1 

而/ lib64是/ usr / lib64的符号链接。并且,/usr/lib64/libgcc_s.so.1是指向/usr/lib64/libgcc_s-4.9.2-20150212.so.1的符号链接,它作为真实文件(92816字节)存在。



所以,我不知道ld的问题是在-lgcc_s。 crtbegin是无处可找,gcc(no _s)无处可找。



yum install libgcc说它已经安装和最新版本,无所事事。 / p>

因为我有一个安装的clang源代码构建,我可以重新构建clang,这次使用clang而不是gcc,摆脱依赖? (也许候选GCC安装位会消失。)



我可以强制-stdlib = c ++和-lc ++ abi为默认值, libc ++和libc ++ abi安装没有gcc?

解决方案

花了一些时间尝试使用libc ++和libc + + abi没有GCC,我发现这的确是可能的,即使有点问题,给定当前状态的LLVM / clang。除了小测试程序,我已经能够构建CMake和一些其他软件包用C ++编写没有安装GCC,并且生成的二进制文件独立于libstdc ++;他们只依赖libc ++ / libc ++ abi根据ldd输出。不幸的是,我还没有能够使用GCC构建的clang本身构建clang。我试过不同的Linux平台(Fedora 21 32位,Amazon Linux版本2015.3(基于RPM)64位,CentOS 7.1 64位和Ubuntu 14.04 64位)。



虽然可以使用libc ++ / libc ++ abi构建软件,而不依赖于libstdc ++和没有GCC编译器,但是典型的Linux安装与libgcc和libstdc ++紧密相关,不实用。尝试删除这两个包,您将看到系统的多少取决于它们。即使在FreeBSD 10.1上,由于clang是默认编译器,没有安装GCC,libgcc.a,libgcc_s.so和一些crt * .o文件在构建由-v选项显示的程序时使用。此外,在FreeBSD 10.1中,生成的二进制文件依赖于libgcc,根据ldd。在Ubuntu上,有dpkg作为包管理器,文件

  libgcc.a 
libgcc_s.so
crtbegin.o
crtbeginT.o
crtbeginS.o
crtendS.o
crtend.o

在libgcc-devel包中,而在基于RPM的系统上,如Fedora,这些都在gcc包中。此外,您可能需要这些文件,即使我不需要他们为我尝试构建的代码:

  crtfastmath .o 
crtprec32.o
crtprec80.o
crtprec64.o

因此,可能会认为上述文件更好地属于libgcc,而不是在gcc。就我可以告诉,以下需要在删除gcc包之前在基于RPM的系统上进行:



1)创建符号链接

  libgcc_s.so  - > libgcc_s.so.1所在目录中的libgcc_s.so.1 



2)将上面列出的crt * .o文件复制到该目录。



3)在同一目录下创建符号链接libstdc ++ .so.x应该已经存在; x是一个数字):

  libstdc ++ so  - > libstdc ++。so.x 



如果你要使用libstdc ++,你只需要这个;这不是必需的,如果你只打算使用libc ++。在一些
系统libstdc ++。所以,它是libstdc ++。so.x的符号链接属于libstdc ++包,由libstdc ++ - devel包放置到GCC库目录中,所以你可以在卸载GCC后删除该目录



现在您应该可以执行以下操作:



1)构建C程序:

  clang progname.c 

2)使用libstdc ++ headers / libs构建C ++程序:

  clang ++ -I< header of headers> progname.cpp 



在我看过的基于RPM的系统上,libstdc ++头文件是



3)使用libc ++ headers / libs构建一个C ++程序:

  clang ++ -I /< header of headers> progname.cpp -nodefaultlibs -lc ++ -lc ++ abi -lm -lc -lgcc -lgcc_s 



请参阅 http://libcxx.llvm.org/ 了解更多信息。当使用libc ++ / libc ++ abi构建C ++代码时,您可以使用-stdlib = libc ++而不是-I标志,但是在我的测试中,只有从源代码构建clang,而不是从仓库安装clang(您可以安装clang从repo并使用它来构建libc ++ / libc ++ abi;或者你可以使用gcc来构建libc ++(abi),然后删除gcc并使用libs与repo提供的clang)。



当使用clang + libc ++配置软件包来构建它时,您可能需要设置以下内容:

  LIBS = -  nodefaultlibs -lc ++ -lc ++ abi -lm -lc -lgcc_s -lgcc
CXX = clang ++
CXXFLAGS = - stdlib = libc ++
CC = clang

请注意,要配置CMake源以构建它,我不得不使用如下所示的包装脚本:

 #!/ bin / bash 

MYLFLAGS = - nodefaultlibs -lc ++ -lc ++ abi -lm -lc -lgcc_s -lgcc

#当我们只想编译时捕获大小写;这有助于我们避免一些警告:
if echo$ @| egrep(^ -c | -c | -c $)> / dev / null 2>& 1;那么
MYLFLAGS =
fi

/ usr / local / bin / clang ++ -stdlib = libc ++$ @$ MYLFLAGS


有关更多信息,请参阅我的文章 http://www.omniprog.info/clang_no_gcc.html


Can you (reasonably) get Fedora 21 to where it only has llvm/clang/libc++/libc++abi? (I found some things suggesting no, but they were all about 3 years old, and llvm/clang has come a long way since then.)

With a fresh install, I tried

yum install gcc gcc-c++
(downloaded, built, installed llvm/cfe(clang)/compiler-rt/libcxx/libcxxabi from svn)
yum remove gcc gcc-c++
added to /etc/profile: export CC=/usr/local/bin/clang \ export CXX=/usr/local/bin/clang++
(in case of hard wiring)
ln -s /usr/local/bin/clang /usr/local/bin/gcc
ln -s /usr/local/bin/clang /usr/local/bin/cc
ln -s /usr/local/bin/clang++ /usr/local/bin/g++
ln -s /usr/local/bin/clang++ /usr/local/bin/c++
ldconfig

I was all happy, then went to build something, and I got:

ld: cannot find crtbegin.o
ld: cannot find -lgcc
ld: cannot find -lgcc_s

clang -v includes

Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.9.2

ldconfig && ldconfig -p | grep libgcc does show

libgcc_s.so.1 (libc6,x86-64) => /lib64/libgcc_s.so.1

And /lib64 is a symlink to /usr/lib64. And, /usr/lib64/libgcc_s.so.1 is a symlink to /usr/lib64/libgcc_s-4.9.2-20150212.so.1, which exists as a real file (92816 bytes.)

So, I don't get what ld's problem is on -lgcc_s. crtbegin is nowhere to be found, and gcc (no _s) is nowhere to be found.

yum install libgcc says it's already installed and latest version, nothing to do.

Since I have an installed clang source build, can I re-build clang, this time using clang rather than gcc, to get rid of the dependency? (Maybe then the "candidate GCC installation" bit goes away.)

Can I force -stdlib=c++ and -lc++abi to be default, or at least have libc++ and libc++abi installed without gcc?

解决方案

Having spent some time trying to get clang to work with libc++ and libc++abi without GCC, I have found that it is indeed possible, even if a bit problematic given the current state of LLVM/clang. In addition to small test programs, I've been able to build CMake and some other software packages written in C++ with no GCC installed, and with the resulting binaries being independent of libstdc++; they only depend on libc++/libc++abi according to ldd output. Unfortunately, I haven't been able to build clang itself with clang that was build using GCC. I've been experimenting on different Linux platforms (Fedora 21 32-bit, Amazon Linux release 2015.3 (RPM-based) 64-bit, CentOS 7.1 64-bit, and Ubuntu 14.04 64-bit).

Even though one can build software with clang using libc++/libc++abi without dependency on libstdc++ and without GCC compiler present, a typical Linux installation is so tied to libgcc and libstdc++ that getting rid of these is not practical. Try removing these two packages and you will see how much of the system depends on them. Even on FreeBSD 10.1, with clang being the default compiler and no GCC installed, libgcc.a, libgcc_s.so, and a few crt*.o files are used when building a program as revealed by the -v option. Also, on FreeBSD 10.1, resulting binaries depend on libgcc according to ldd. On Ubuntu, which has dpkg as the package manager, the files

   libgcc.a
   libgcc_s.so
   crtbegin.o
   crtbeginT.o
   crtbeginS.o
   crtendS.o
   crtend.o

are in the libgcc-devel package, while on an RPM-based system, such as Fedora, these are in the gcc package. In addition, you might possibly need these files, even though I didn't need them for the code I tried building:

   crtfastmath.o
   crtprec32.o
   crtprec80.o
   crtprec64.o

Thus one might argue that the aforementioned files better belong in libgcc, rather than in gcc. As far as I can tell, the following needs to be done on an RPM-based system before removing the gcc package:

1) Create the symlink

libgcc_s.so -> libgcc_s.so.1

in whatever directory libgcc_s.so.1 is located.

2) Copy the crt*.o files listed above to that directory.

3) In the same directory create the symlink (libstdc++.so.x should already be there; x is a number):

libstdc++.so -> libstdc++.so.x

You only need this if you are going to use libstdc++; this isn't needed if you only plan to use libc++. On some systems libstdc++.so, which is a symlink to libstdc++.so.x belonging to the libstdc++ package, is placed by the libstdc++-devel package into the GCC library directory, so you can remove that directory after uninstalling GCC and just create the symlink in the same directory where libstdc++.so.x lives.

Now you should be able to do the following:

1) Build a C program:

clang progname.c

2) Build a C++ program using libstdc++ headers/libs:

clang++ -I<location of headers> progname.cpp

On RPM-based systems I've looked at, the libstdc++ headers are part of the libstdc++-devel package and their location can be found from rpm -ql on the package.

3) Build a C++ program using libc++ headers/libs:

clang++ -I/<location of headers> progname.cpp -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc -lgcc_s

The location of the headers is wherever they were installed when you built LLVM+clang etc.

Please see http://libcxx.llvm.org/ for additional information. When building C++ code using libc++/libc++abi, you may use -stdlib=libc++ instead of the -I flag, but in my testing that only worked with clang built from source, not with clang installed from a repository (you can install clang from repo and use it to build libc++/libc++abi; or you can use gcc to build libc++(abi), then remove gcc and use the libs with the repo-provided clang).

When configuring a software package to build it using clang + libc++, you might need to set the following:

LIBS="-nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc"
CXX=clang++
CXXFLAGS="-stdlib=libc++"
CC=clang

Please note that to configure CMake source in order to build it I had to use a wrapper script like this:

#!/bin/bash

MYLFLAGS="-nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc"

# Catch the case when we only want to compile; this helps us avoid some warnings:
if echo "$@" | egrep "(^-c | -c | -c$)" >/dev/null 2>&1; then
MYLFLAGS=""
fi

/usr/local/bin/clang++ -stdlib=libc++ "$@" $MYLFLAGS

It might be useful for other purposes as well.

For more information please see my article at http://www.omniprog.info/clang_no_gcc.html

这篇关于Fedora 21与铛,没有gcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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