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

Replacing gcc and g++ with GNU version in macOS

时间:2023-09-15 17:33:32浏览次数:70  
标签: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.

标签:bin,gcc,GNU,Replacing,clang,++,version,usr
From: https://www.cnblogs.com/hongyugao/p/17705571.html

相关文章

  • 使用gcc内置CAS函数实现spinlock
     Built-inFunction:bool__atomic_compare_exchange_n(type*ptr,type*expected,typedesired,boolweak,intsuccess_memorder,intfailure_memorder)Thisbuilt-infunctionimplementsanatomiccompareandexchangeoperation.Thiscomparesthecontents......
  • 系统测试AC5. AC6. IAR和GCC调试效果,MDK AC6不开优化调试乱跳,甚至倒序执行
    首先感谢大家对上一个视频的点评回复,非常有意义的讨论,这次AC6的表现更新惊呆,不开优化都可以乱跳。【实验目的】同样的程序代码,目的是测试C环境的调试现象。【实验版本】IAR版本  :9.3xMDK版本:5.3x,含AC5和AC6EmbeddedStudio:使用GCC,版本V7.1X【视频展示】https://www......
  • gcc安装实战归纳
     安装gcc遇到如下问题:意思就是你的ubuntu版本太高了,但是你要安装的软件版本太低了,所以说嘛!你就得换个强一点的安装器 推荐                 【不推荐使用】aptitude[这玩意儿慎用!可能会导致重装系统]默认的Ubuntu软件源包含了一个软件包组,名称为"build-es......
  • linux gcc rpath
    linux下程序运行时如果想要到指定路径下查找依赖库,除了使用LD_LIBRARY_PATH,还可以使用编译选项rpath:g++-Wl,-rpath='$ORIGIN/libs'-omainmain.cpp-L.-lmylib那么只要把libmylib.so放到libs目录下,main即可正常执行。如果是在QT中,则改为:QMAKE_LFLAGS+="-Wl,-rpath='\$......
  • gcc 常见编译参数
    -c只激活预处理,编译,和汇编-S只激活预处理和编译-E只激活预处理-C在预处理的时候,不删除注释信息-g只是编译器,产生调试信息。-o制定目标名称-w不生成任何警告信息。-M生成文件关联的信息。......
  • mac上的find与gnu find
    linux上用的find属于gnufind,如果是查找当前路径是可以省略.的,只需要find-name"xxx"而mac上自带的find是bsdfind,.不可以省略,否则会报错/usr/bin/find:illegaloption--n可以手动安装https://www.gnu.org/software/findutilsbrewinstallfindutilsIfyouneedtouse......
  • GCC编译器
    (1)预处理(preprocessing)、编译(compilation)、汇编(assembly)和链接(linking) gcc-E-ohello.ihello.c //预处理(preprocessing) gcc-S-ohello.shello.i //编译(compilation) gcc-c-ohello.ohello.s //汇编(assembly) gcc-ohellohello.o //链接(link......
  • conda中安装GCC
    一般在linux中gcc都是安装在系统路径下,有的时候需要更换gcc版本但是又没有系统权限,这时候就可以考虑使用conda下集成的gcc。  安装方法:condaconfig--addchannelsconda-forgecondainstallgcc=12   condainstallgcc=12 -c conda-forge      ......
  • GCC实现多文件编译,静态库,动态库
    GCC实现多文件编译,静态库,动态库一代码 //add.hintadd(inta,intb);  //add.cintadd(inta,intb){  returna+b;}  //main.c #include<stdio.h>#include"add.h" voidmain(){   printf("3+2=%d\n",add(3+2));} 二......
  • Docker|--E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of the
    错误apt-keyadv--keyserverkeyserver.ubuntu.com--recv-keys871920D1991BC93CE:gnupg,gnupg2andgnupg1donotseemtobeinstalled,butoneofthemisrequiredforthisoperation解决方案apt-getupdate&&apt-getinstall-ygnupg2#或者apt-getu......