How to use C++14 with Xcode? - macos

I just bought a macbook air,i installed Xcode but its not having c++ 14,i read some threads on stackoverflow and they are mentioning something like clang,what is clang and how do I complete this process??,please explain in layman terms,i am completely new to mac.

Clang/LLVM are Macs' default compiler.
Now, about C++14:
Clang has experimental support for some proposed features of the C++ standard following C++14, provisionally named C++1z. Note that support for these features may change or be removed without notice, as the draft C++1z standard evolves.
You can use Clang in C++1z mode with the -std=c++1z option.
from Clang/LLVM's documentation
So just add "-std=c++1z" to your compile options in Xcode (without the quotes).

I was just now having the same problem. I found this in the build settings:
The drop-down menu has a C++14 option. It solved the problem for me.

Related

Can I use GCC compiler AND Clangd Language Server?

I am working on a project that uses a GCC library (SFML), which is not available for clang, as far as I know. I am using COC with vim for code completions, but for C++ it needs clangd. Is there a way to use GCC as my compiler, but still use the clangd language server?
I have also heard that there may be a way to make clang recognize GCC libraries/headers, but I've never been able to make it work right. If somebody could point me in the right direction there that would be helpfull too. But I'm used to GCC (I've been using it since I started programming C++), so being able to use clangd and GCC would be preferable.
Yes it is. I do it with ccls (which is clang based as well).
Given my installation of clang is not the standard one (I compile it, tune it to use libc++ by default, and I install it somewhere in my personal space) I have to inject paths to header files known by clang but unknown by other clang based tools.
I obtain them with
clang++ -E -xc++ - -Wp,-v < /dev/null
Regarding the other options related to the current project, I make sure to have a compile_commands.json compilation database (generated by CMake, or bear if I have no other choice), and ccls can work from there. I expect clangd to be quite similar in these aspects.
Ops, answered the wrong question.
But for those who use ccls:
create a .ccls file in your project directory and append --gcc-toolchain=/usr to it.
use this tool to generate a compile_commands.json file
see https://github.com/MaskRay/ccls/wiki/FAQ#compiling-with-gcc

How to create visual studio projects that use LLVM

I'm trying to use LLVM to implement a compiler for a toy language. Something like the Kaleidoscope Tutorial. I'm using Visual Studio on 64 bit Windows.
I've managed to build LLVM and clang using VS, but now I want to use the LLVM libraries in my own project. It seems like a silly question but how to I do this? What compiler options do I need? What libraries should I link with etc. etc.
As far as I can see this isn't covered anywhere in the LLVM documentation although I could have easily missed it.
I discovered llvm-config which is designed to solve the problems I'm having. It often seems to give incorrect information (for instance llvm-config --includedir is wrong) but it at least gives me a list of libraries to link with.
I suppose I could also use CMake to generate project files, but CMake seems to be difficult to learn from free resources.

How can I find out which c++ compiler is Xcode 5 using?

I am currently writing c++ code and compiling using Xcode. I was wondering: How can I find out which c++ compiler is Xcode 5 using?
I would like to know that to make sure that the program I am writing is compilable on other computers that don't necessarily use the same compiler.
Thanks in advance!
You can also check your target's build settings to see what the current setting is. However, Xcode 5 only uses the LLVM 5.0 compiler. GCC is no longer used.
https://developer.apple.com/technologies/tools/features.html

Using boost from xcode 4.4 - unable to access the regex library

I am fairly new to c++ and I need to use regular expressions and more libraries of that type that do not come with Xcode. I have found boost but i dont know how to install it. I thought it worked but it did not recognize the regex library for boost. I typed it in correctly.
thanks
If you use libc++, which comes with Xcode 4.4, then you can use the C++11 <regex> library. Just go to the project's build settings and set the C++ standard library to be libc++. Turn on C++11 while you're at it.

Is there a list of pragmas supported in Xcode?

Is there a list of pragmas supported in Xcode? I only know of #pragma mark. Where would I look to learn about any others?
GCC online manual, see here. Depending on your XCode settings, you can use GCC 4.0, 4.2, 4.4 (if present on your system) or even LLVM/GCC 4.2. Please refer to proper compiler version docs for specific information.

Resources