user1368198
user1368198

Reputation:

How can i make my C++ code buildable with clang on Mac?

I have a bunch of .cpp and .c files and i use gcc/make to build a project. On Mac there is only gcc 4.2. It is very old and puts a lot of limitations on the language. I've heard clang is the default compiler for Mac. How can i change my makefiles to use clang?

Upvotes: 2

Views: 4561

Answers (2)

Roman A. Taycher
Roman A. Taycher

Reputation: 19505

You could try replacing CC=g++ with CC=clang in you makefiles or doing CC=clang make instead of make and see if it compiles.

If you use gnu c/c++ extensions or gcc command line options it may not compile, in that case you can try googling for help.

Upvotes: 2

Nick Bastin
Nick Bastin

Reputation: 31339

For starters, GCC 4.2 is not "very old and puts a lot of limitations on the language."

That being said, your Mac, if it has GCC 4.2 installed, should also have clang installed. Xcode includes both clang and GCC (built with LLVM), as clang and gcc/g++ respectively. Either:

  • change your makefiles to point to clang directly
  • set the CC environment variable to clang
  • soft link g++ to clang if you want to be really hamfisted about it.

Any one should do the trick.

Upvotes: 3

Related Questions