Why c programs not running on my Mac.

Is Xcode necessary for compiling C language files. It always throws me a -g clang error but once I installed and tried compiling it compiled. Then again after uninstalling it throws the same error. So is Xcode must and is there any other alternative.

Posted on Jan 26, 2023 5:12 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 26, 2023 10:28 AM

To compile C code you must either install Xcode or install the Command Line Tools package from Apple's developer downloads site.


https://developer.apple.com/download/


There is a Command Line Tools package for each version of macOS. Install the one for your version.

4 replies

Jan 26, 2023 12:53 PM in response to Vikraman6000

Properly compiled and built C programs run just fine, for the usual C definition of "just fine".


C compilation requires the presence of a C compiler or ilk, same as everywhere else.


You can use Xcode (which includes the IDE and the command-line tools including the Clang C compiler), or (just) the Xcode command-line tools (without the IDE), or can load a compiler of your choice using Homebrew or otherwise. Clang, gcc, pcc, and various other C compilers are around.


Homebrew has gcc and LLVM available, and both of which are... large. I haven't confirmed the LLVM build includes Clang, but I'd expect it does.


You could also use the Emscripten C compiler too, and compile your C code into WebAssembly and run the code directly in a web browser with WebAssembly support.


And Microsoft Visual Studio Code IDE is around, but I'd expect that needs the command line tools.


I find using the Xcode IDE makes C work faster and easier.


Yeah, there are inherently trade-offs with an IDE or any other tooling.

Jan 26, 2023 11:06 AM in response to Vikraman6000

The operating system does not install a compilation suite. You must do that and Mark Szymczyk has shown you where to get it.


Since Apple does not correlate the operating system that a particular CommandLine Tools package should be installed, one can issue the following in the Terminal to get the last available CLT package for the current operating system:


xcode-select --install


and that will pop the following dialog that will only install the CommandLine Tools package and provide access to the clang and clang++ compilers. This will require an administrator password to begin the installation.




This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Why c programs not running on my Mac.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.