Compiler for mac os

Hello,

I just tried using Mac for programming, I need to find a compiler. When I tried

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)

typing in the terminal nothing happened so far. Any suggestions?

You can try this - https://developer.apple.com/xcode/

All the threads Ive seen recommends this one.
Last edited on
closed account (2LzbRXSz)
I agree. I've been using Xcode since I started programming in C++ and it works like a charm. If you've never worked in an IDE/compiler before, it may look sort of intimidating/complicated but it's pretty simple.

If you'd rather work in something that's cross platform, I recommend Eclipse or Code::Blocks. Eclipse can give you trouble setting it up though (at least, it was pretty troublesome for me) but has a simple solution to fix it (a solution that I can't actually remember right now but I just know it's fixable).
Hi,

I`m now actually building gcc from source, see further

https://ftp.gnu.org/gnu/gcc/gcc-4.9.2/

I also had to get some other libraries which are packed as xz, gz and lz formats.
My current worry is that how can I extract these?

I downloaded the source for unarchiver from here:
http://unarchiver.c3.cx/unarchiver

Now I only need to know how to use it
I have no idea :D

You're probably going through more trouble than you need. Apple's spin of the Clang compiler is quite stable and probably supports OS X better than gcc does, now that Apple ceased to use it.

Is there any reason why you can't use the Xcode bundle? It doesn't just include an LLVM compiler toolchain, but a number of other essential programmers' tools (such as Ruby). You're not restricted to using the IDE if you don't like it, just remember to link against libc++ as by default Apple Clang does not.

EDIT: Also, most of LLVM's tools take the same command line arguments as their GCC equivalents. One notable exception is LLDB.

-Albatross
Last edited on
you can Install GCC Compiler with Xcode -
nixCraft
Hi,

The Xcode package is so huge, sorry but it takes too much memory. Also, why to register if I can get gcc without it ;D

I tried to actually follow the instructions from here https://solarianprogrammer.com/2013/06/11/compiling-gcc-mac-os-x/

1
2
3
4
5
6
7
8

cd Downloads
host-001:Downloads user$ cd gmp*
-bash: cd: gmp-6.0.0a.tar.lz: Not a directory
host-001:Downloads user$ mkdir build && cd build
host-001:build user$ ../configure --prefix=/usr/gcc-4.9.2 --enable-cxx
-bash: ../configure: No such file or directory



Sorry but I`m now quite out of this thing…

Please someone tell me what I did wrong in the terminal window...
gmp-6.0.0a.tar.lz

You haven't extracted the files yet. However... I should refer you to this.

https://gcc.gnu.org/install/prerequisites.html
Tools/packages necessary for building GCC: ISO C++98 compiler


Apple doesn't bundle a compiler with the base installation of Mac OS, so you're trying to build a compiler without a compiler. Furthermore, I'm not even sure if GCC's standard libraries properly support Mac OS ever since Apple dropped them.

Getting Xcode really is the way to go here, even if it's bulky.

-Albatross
Last edited on
Yep, my mistake was to download the lz file, it should be bz.

Now when done that I get this error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

mkdir build && cd build
host-001:build user$ ../configure --prefix=/usr/gcc-4.9.2 --enable-cxx
checking build system type... x86_64-apple-darwin11.4.2
checking host system type... x86_64-apple-darwin11.4.2
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ../install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... no
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=64
checking compiler gcc -O2 -pedantic -fomit-frame-pointer -m64 ... no
checking compiler cc -O ... no
checking ABI=x32
checking compiler gcc -O2 -pedantic -fomit-frame-pointer -mx32 ... no
checking compiler cc  ... no
checking ABI=32
checking compiler gcc -m32 -O2 -pedantic -fomit-frame-pointer ... no
checking compiler gcc -O2 -pedantic -fomit-frame-pointer ... no
checking compiler icc -no-gcc ... no
checking compiler cc -O ... no
configure: error: could not find a working compiler, see config.log for details



I looked at config.log, but can`t understand much of it.
Im not sure if this will help but, there are plenty of video tutorials on youtube showing how to install xcode. Probably also some on google aswell.
TheRabbitologist wrote:
Apple doesn't bundle a compiler with the base installation of Mac OS
autoconf wrote:
configure: error: could not find a working compiler, see config.log for details


Seriously, if you don't want to install Xcode, at least install the Xcode command line tools, which are a separate package. http://osxdaily.com/2012/07/06/install-gcc-without-xcode-in-mac-os-x/

-Albatross
closed account (2LzbRXSz)
Xcode command line tools are great. A++ in my book. They're all you need if you're programming in C++ anyways.
I just compiled and installed gcc and command line tools but now getting this error:

g++-4.9.2 Documents/program1.cpp -o fast
g++-4.9.2: error: Documents/program1.cpp: No such file or directory
g++-4.9.2: fatal error: no input files


Here is the code in Documents/program1.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

*/ Program to count blanks, tabs and newlines */

#include <stdio.h>

/* count lines in input */

int main()
{

   int c, n1, n2, n3;
   
   while ((c = getchar()) != EOF)
        if (c == ' ')
         ++n1;
        else if (c == '\t')
        ++n2;
        else if (c == '\n')
        ++n3;
        
  printf(" Number of blanks: %d\n",  number of tabs is %d\n", number of newlines is %d.\n", n1, n2, n3);
  
  return 0;
  
}









Last edited on
printf(" Number of blanks: %d\n", number of tabs is %d\n", number of newlines is %d.\n", n1, n2, n3);

This is also incorrect. Your middle sentence does not have any quotes around it.

Maybe you want something like this?

printf("Number of blanks: %d\nNumber of tabs is %d\nNumber of newlines is %d.\n", n1, n2, n3);
Last edited on
Maybe I should save the file in my Home directory?

Sorry, I was not asking to analyze the semantics of my program, I just need to get stuff to compile.
Last edited on
Please, if I save the file in my home directory I can just compile it without needing to cd ?

I use TextMate editor, how can I save it to home directory or where is it located?
1
2
3
4
5
6
7
8
9
10
11


kjkjkjk     jkjkj    


lod   D

 Number of blanks: 32767
Number of tabs is 1828081753
Number of newlines is 32772.


What does those result mean? Now I got the program to work, anyway how can i avoid writing export PATH=/usr/gcc-4.9.2/bin:$PATH
every time I open terminal?
Last edited on
> What does those result mean?
¿why bother yourself in posting your current code?
you didn't initialised your variables

> how can i avoid writing (...) every time I open terminal?
1) put it in the startup file of your shell
a) don't use exotic paths for your installed programs
I just created the bash profile (in my user folder) and put the
export PATH=/usr/gcc-4.9.2/bin:$PATH

command there, and now it`s giving me this error:

g++-4.9.2 Documents/program1.cpp -o fast
-bash: g++-4.9.2: command not found


why not just use clang? and i believe the proper exe name would be g++
Topic archived. No new replies allowed.