How to change clang to gcc in MacOs? - c

Is it possible to prevent MacOS to stop mapping gcc to clang?
i want to run a tool its dependency is with gcc and not for clang. So i installed gcc but since i typing in gcc -v i am getting the mapped version to clang
how to prevent this?
this is how am i getting
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Related

M_PI_2 missing from clang on Windows

I make use of M_PI_2 from math.h in my source code.
This works fine for my Linux, OSX, iOS and Android builds.
When I use the clang compiler for Windows, I get:
use of undeclared identifier 'M_PI_2'
Why is there no M_PI_2 for my clang compiler on Windows? I compile with _POSIX_C_SOURCE=200112L
$ clang --version
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
So, from ucrt/corecrt_math_defines.h I see that:
"Define _USE_MATH_DEFINES before including to expose these macro definitions..."

How can I install gcc 4.2.1 on OSX Sierra?

I'm using the Bochs emulator and for my class we're using gcc 4.2.1. I believe I've gotten Bochs running, but now I need to compile our programs which are compatible with gcc 4.2/.1.
I understand OSX uses an alias for gcc 4.2.1, but how can I use gcc specifically and not clang?
Edit: GCC 4.6.3 not 4.2.1 sorry
You can install previous version of gcc pretty easily using homebrew.
If you have homebrew installed you can get gcc 4.9 by running
brew install gcc#4.9
After it is installed gcc will still map to the clang that came with your mac. The newly installed gcc will be installed at /usr/local/bin and be called something like gcc-4.
You can find the exact executable name using
ls /usr/local/bin | grep gcc
Hopefully 4.9 is close enough to 4.6 for your purposes.

Clang stdio,h file not found

I installed clang with Visual Studio and then built the highlighted project as it's said in the documentation.
The build was successful, however when I try this:
clang -cc1 -analyze -analyzer-checker=core.DivideZero test.c
It says:
test.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
I tried many suggestions but nothing worked.
However if I do something like this it works
clang --analyze text.c
I don't know if this uses all the available checkers. I need to write my own checker and test it...
Any ideas?
Output of clang --version
clang version 7.0.0 (trunk 322536)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\path\build\Debug\bin
Yes, I have an idea. Remove -cc1 or <stdio.h>. According to the clang FAQ this is your error. It states quite explicitly, giving your precise example:
$ clang -cc1 hello.c
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
Reading on, it gives other alternative solutions, as well as a useful explanation, which you should certainly read in its entirety, since it's our job as programmers to read the manuals for the technology we use.
clang -cc1 is the frontend, clang is the driver. The driver invokes the frontend with options appropriate for your system. To see these options, run:
$ clang -### -c hello.c
Some clang command line options are driver-only options, some are frontend-only options. Frontend-only options are intended to be used only by clang developers. Users should not run clang -cc1 directly, because -cc1 options are not guaranteed to be stable.
If you want to use a frontend-only option (“a -cc1 option”), for example -ast-dump, then you need to take the clang -cc1 line generated by the driver and add the option you need. Alternatively, you can run clang -Xclang <option> ... to force the driver pass <option> to clang -cc1.
The emphasis is mine. This should give you enough guidance to get what you need done.

Install GCC on Mac OS high sierra

I've already visited the following answer but my question is different.
Install GNU GCC on mac
Mac OS ships with Clang and somehow /usr/bin/gcc is linked to Clang tool I assume because of this line.
gcc
clang: error: no input files
Any idea on how can I install https://gcc.gnu.org/ standalone on my system?
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin17.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Any idea on how can I install https://gcc.gnu.org/ standalone on my system?
Generally speaking: Don't. That isn't a standard configuration; Clang is the recommended compiler for current macOS systems.
If you have a very good reason, you can use Homebrew to install GCC (brew install gcc). Keep in mind that it cannot be used to build native macOS applications.

how to find gcc version on mac

I am using OS 10.9 on mac machine. I want to know the version of gcc I am using. So I tried gcc --version on terminal and it results :
$ gcc --version
Configured with: --prefix=/Applications/Xcode5-DP.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode5-DP.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.1.58) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Here in output, there is no detail related to gcc but clang is there. I am confused
whether gcc command executes clang or gcc(gnu).
You seem to not actually have gcc on your path. As of recent versions of Xcode, it installs a "gcc" that is instead a link to Clang.
gcc -dumpversion | cut -f1 -d.
-dumpversion Print the compiler version (for example, 3.0) — and don't do anything else.
The same works for following compilers/aliases:
cc -dumpversion
g++ -dumpversion
clang -dumpversion
tcc -dumpversion
Be careful with automate parsing the GCC output:
Output of --version might be localized (e.g. to Russian, Chinese, etc.)
GCC might be built with option --with-gcc-major-version-only. And some distros (e.g. Fedora) are already using that
GCC might be built with option --with-pkgversion. And --version output will contain something like Android (5220042 based on r346389c) clang version 8.0.7 (it's real version string)
The tools supplied by Apple have been switched from GCC to Clang. The gcc command is linked to clang as a convenience. In OS X 10.9, you do not have GCC on your system unless you have installed it independently of Apple packages.
In case you installed gcc via brew install, it might've got installed as gcc-11.
You can run brew info gcc to get path where it is installed and get exact name of the binary by listing the directory.
$ brew info gcc
gcc: stable 11.2.0 (bottled), HEAD
GNU compiler collection
https://gcc.gnu.org/
/usr/local/Cellar/gcc/11.2.0_3 (2,163 files, 459.8MB) *
...
$ ls /usr/local/Cellar/gcc/11.2.0_3/bin
c++-11 gcc-ar-11 gcov-dump-11 gfortran x86_64-apple-darwin21-g++-11 x86_64-apple-darwin21-gcc-ranlib-11
cpp-11 gcc-nm-11 gcov-tool-11 gfortran-11 x86_64-apple-darwin21-gcc-11 x86_64-apple-darwin21-gcc-tmp
g++-11 gcc-ranlib-11 gdc lto-dump-11 x86_64-apple-darwin21-gcc-ar-11 x86_64-apple-darwin21-gdc-11
gcc-11 gcov-11 gdc-11 x86_64-apple-darwin21-c++-11 x86_64-apple-darwin21-gcc-nm-11 x86_64-apple-darwin21-gfortran-11
Then using gcc-11 -v will get you actual version of gcc installed.
$ gcc-11 -v
Using built-in specs.
COLLECT_GCC=gcc-11
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.2.0_3/bin/../libexec/gcc/x86_64-apple-darwin21/11/lto-wrapper
Target: x86_64-apple-darwin21
Configured with: ../configure --prefix=/usr/local/opt/gcc --libdir=/usr/local/opt/gcc/lib/gcc/11 --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran,d --program-suffix=-11 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0_3' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-libphobos --build=x86_64-apple-darwin21 --with-system-zlib --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Homebrew GCC 11.2.0_3)
gcc -dumpversion | cut -f1 -f2 -f3 -d.

Resources