首页 > 其他分享 >Replacing gcc and g++ with GNU version in macOS

Replacing gcc and g++ with GNU version in macOS

时间:2023-10-21 22:02:41浏览次数:58  
标签:bin gcc GNU Replacing clang ++ version usr

After we install Xcode Command Line Tools, we will get gcc and g++ in /Library/Developer/CommandLineTools/usr/bin and the same contents in /usr/bin. But the problem is that gcc and g++ are same as clang and clang++. Proof can be obtained from the following content.

% gcc --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

% gcc++ --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

How can we replace them with GNU version ?

  1. Install the GNU gcc(contains g++) We can use brew install gcc-xxx (xxx is the version number of gcc) After the installation process, we will get the gcc-xxx and g++-xxx in /opt/homebrew/bin

  2. Create a symbol link for original binary file gcc-xxx and g++-xxx Because the original filename is long which contains the version number, we want use the gcc and g++ command directly. So we need to create a symbol links for them. Refer to the gcc and g++ from the xcode command line tools, we want create two symlinks in usr/bin. However, when we excute ln -s gcc /usr/bin/gcc, we will get the following result.

ln: /usr/bin/gcc: Operation not permitted

Although we use sudo, we still couldn't create a symlink in /usr/bin. In fact, we can use some special operations to avoid this protection mechanism, but thinking about the system safety, we will use other reasonable operations.

The answer is creating symbolic links in /usr/local/bin, it means users's bin not system's bin.

  1. Adjust the order of /usr/bin and /usr/local/bin in PATH environmental variable Why we need this operation? Because we want to use gcc and g++ directly in termial, so we need to solve the duplicate name problem of these commands in /usr/bin and /usr/local/bin. And we know when system finds commands, it follows the order of PATH environment variable, so we ought to put /usr/local/bin before /usr/bin in PATH environment variable. In fact, the default situation is same as that.

Reference

标签:bin,gcc,GNU,Replacing,clang,++,version,usr
From: https://blog.51cto.com/u_14882565/7969749

相关文章

  • gcc对构造函数的调用生成
    identifierC++的前端对identifier做了扩展,在每个identifier中还包含了两个cxx_binding字段:namespace_bindings和bindings。当通过字符串找到一个identifier的时候,同时顺带获得了两个binding信息。/*Language-dependentcontentsofanidentifier.*/structGTY(())lang_id......
  • 【发现一个问题】macos m2 下无法使用 x86_64-linux-musl-gcc 链接含有 avx512 指令
    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢!cnblogs博客zhihuGithub公众号:一本正经的瞎扯一开始是使用golang中的cgo来编译:envCC=cCGO_ENABLED=1GOOS=linuxGOARCH=amd64\CGO_CFLAGS="-mavx-mavx2-mavx512f-mavx512vl-mavx512bw-O2"\gobu......
  • Linux下源码编译gcc指定版本
    首先你得有一个编译器才能编译编译器下载GCC源码并解压wgethttps://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-9.4.0/gcc-9.4.0.tar.gztar-zxvfgcc-9.4.0.tar.gz这里我选择了gcc-9.4.0版本下载依赖文件cdgcc-9.4.0./contrib/download_prerequisites编译前配置......
  • centos 6.10 安装 gcc9.4
    centos6.10安装gcc9.4下载gcc9.4下载地址:https://mirrors.tripadvisor.com/gnu/gcc/gcc-9.4.0/选择gcc-9.4.0.tar.xz下载解压下载的文件进入gcc-9.4.0文件夹,运行:./contrib/download_prerequisites//这一步是安装需要的依赖安装完依赖后执行:mkdirbuild&......
  • 【Linux 基础】gcc、g++多版本间的切换
    在make时可能出现版本过高的问题,因此需要进行版本切换。gcc多版本间的切换(g++配置方法一样,gcc换为g++即可)系统:ubuntu18方法:根据需要同步设置gcc与g++间的版本号1.gcc安装(多版本) sudoapt-getupdate sudoapt-getinstallgcc##安装最新版本,此处为7 sudoapt-getinstall......
  • 浅谈MDK, IAR,CLANG和GCC的局部变量字节对齐处理差异(2023-10-13)
    视频:https://www.bilibili.com/video/BV1CB4y1Z7kA问题由来:早期这个帖子里面的局部变量对齐仅测试了MDKAC5,但项目中使用AC6发现了新问题,看来AAPCS规约研究的还是不够细:https://www.armbbs.cn/forum.php?mod=viewthread&tid=109400当时对局部变量的描述如下:局部变量使用的是......
  • Linux平台下更换GCC版本号
    (1)使用sudoapt-getinstallgcc-xxx下载某个版本gcc,直至在终端输入(以gcc-12为例)gcc-12-v的时候能够输出对应的信息sudoapt-getinstallgcc-12(2)进入ubuntu系统的/usr/bin/文件夹中,此文件夹中存放链接文件(如链接文件gcc)此链接文件能够使得终端在输入gcc-v的时候输出对应......
  • gcc编译过程总结
    第一步:对源文件进行预处理,需要使用的gcc参数为-E#1.预处理,-o指定生成的文件名$gcc-Etest.c-otest.i第二步:编译预处理之后的文件,需要使用的gcc参数为-S#2.编译,得到汇编文件$gcc-Stest.i-otest.s第三步:对得到的汇编文件进行汇编,需要使用的gcc......
  • 地毯和小地毯16 CFR 1630 和16 CFR 1631表面可燃性标准GCC清关认证
    出口美国地垫GCC清关认证美国联邦法律规定,地毯和垫子要符合易燃性标准和其它要求,包括2008年《美国消费品安全改进法》的要求。在地毯和垫子经过检测或合理检测项目后,作为一般用途的地毯和垫子的生产商和进口商必须在一般合规证书(GCC)中认证,地毯和垫子符合适用标准,确保合规和/或按......
  • 地垫/毛绒地毯出口美国GCC清关认证亚马逊gcc认证
    出口美国地垫GCC清关认证美国联邦法律规定,地毯和垫子要符合易燃性标准和其它要求,包括2008年《美国消费品安全改进法》的要求。在地毯和垫子经过检测或合理检测项目后,作为一般用途的地毯和垫子的生产商和进口商必须在一般合规证书(GCC)中认证,地毯和垫子符合适用标准,确保合规和/或按......