简体   繁体   English

如何在Mac上使用clang使我的C ++代码可构建?

[英]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. 我有一堆.cpp和.c文件,我使用gcc / make来构建项目。 On Mac there is only gcc 4.2. 在Mac上只有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. 我听说clang是Mac的默认编译器。 How can i change my makefiles to use clang? 我如何更改我的makefile以使用clang?

For starters, GCC 4.2 is not "very old and puts a lot of limitations on the language." 对于初学者来说,GCC 4.2并不是“很老,并且在语言上有很多限制”。

That being said, your Mac, if it has GCC 4.2 installed, should also have clang installed. 话虽如此,如果您的Mac已安装GCC 4.2,则还应该安装clang Xcode includes both clang and GCC (built with LLVM), as clang and gcc / g++ respectively. Xcode包含clang和GCC(使用LLVM构建),分别作为clanggcc / g++ Either: 或者:

  • change your makefiles to point to clang directly 更改您的makefile以直接指向clang
  • set the CC environment variable to clang CC环境变量设置为clang
  • soft link g++ to clang if you want to be really hamfisted about it. 如果您真的想对它进行软链接,请将g++clang软链接。

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. 您可以尝试在makefile文件中用CC = clang替换CC = g ++或执行CC = clang make而不是make并查看其是否可以编译。

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. 如果您使用gnu c / c ++扩展名或gcc命令行选项,则它们可能无法编译,在这种情况下,您可以尝试使用Google搜索来寻求帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在“.json”配置文件中包含 .dylib 文件? - Mac 上的 VS 代码 iOS - Clang++ 编译器 - 语言:c++ - How can I include .dylib files in ".json" configuration files? - VS Code on Mac iOS - Clang++ compiler - Language: c++ 在Mac OS X 10.6上使用clang 2.8编译C ++代码时,如何解决缺失的符号? - How can I resolve missing symbols when compiling C++ code with clang 2.8 on Mac OS X 10.6? 如何修复并使我的代码在 C++ 中工作? - How can I fix and make my code work in c++? 如何在 Mac 上的 VS Code 上调试 C++ 代码? - How can I debug C++ code on VS Code on Mac? 如何使clang-format跳过c ++代码段 - How to make clang-format skip sections of c++ code 如何更改我的 C++ 代码以使其在 C 中可用? - How can I change my C++ code to make it usable in C? 如何在Mac(C ++)上导出到vsproject? - How can I export to a vsproject on my mac (C++)? 如何使用CLANG作为解析器并使用Python作为脚本语言来解析C ++代码中的宏? - How can I parse macros in C++ code, using CLANG as the parser and Python as the scripting language? 如何使用clang在osx上使用libstdc ++静态链接我的c ++程序? - How can i link my c++ program statically with libstdc++ on osx using clang? 如何使我的C ++代码跨平台兼容? - How can I make my C++ code cross platform capable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM