简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM