How to define g++ or clang++ in xcode 4? - c++

How do I use a c++ compiler (g++ or clang++) to compile a simple c++ project in xCode 4?
You can assume I am in the project, in the Build Settings.
I have in Build Options -> Compiler for C/C++/Objective-C -> Apple LLVM compiler 3.0 and LLVM GCC 4.2 as options.
Is either one appropriate or do I have to install another one?
How do I do that?

For running a simple code with Xcode after running Xcode choose “Create a new XCode project”. (You can also go to “File|New|New Project...” or press Shift-⌘-N). This will bring up a screen in that screen select "Application"then select "Command Line Tool" and then click next .Now enter a name for your project and select type c++ and click next in upcoming screen select a directory for you project and click "create" now you can write codes in main.cpp file in the left panel for running your code just click on "Run" button .
Update:
In Build options click "Build settings" and then click "All" from "C++ language Dialect"and "C++ standard library"tab you can choose the compiler and c++ standard that you want included c++11.

Related

when I try to build on codeblocks and I don't understand why

I used to use dev c++ but now I decided to switch over to codeblocks. dev c++ worked normally but when I try to build on codeblocks nothing happens. I typed out some code compiled it and build it but when I tried to run it a message popped up saying I haven't build it yet and if I would like to build it now. when I clicked yes nothing happend and when I clicked no it would run but not work normally. some youtube videos recommended going to settings then compiler, selecting GNU GCC compiler, going to Toolchain executables and cliicking auto detect. in my case when I clicked auto detect a message saying could not auto-detect installation path of "GNU GCC Compiler". what should I do to fix these errors
install GCC then add its path to environment variable in path then click auto-detect again
if you're on windows
type environment variables in search box
click environment variables button in the dialog
in System Variables group double-click path(add one if missing)
click New then Browse buttons, naviagete to GCC folder
click Ok buttons to confirm, then back to code::blocks to auto-detect
or set the path to GCC manually in Toolchain executables tab

How to compile a project with C++11 under Xcode 8?

This question was asked many times and I failed to replicate all of the solutions I could find. I am unable to find this setting under File->Project Settings (as some suggested). Please be very specific. If you know an answer for Xcode 7, chances are it will work for me too.
It's the same for 7 and 8. From the Project Navigator, select the project. In the main panel, at the top left, select the target. Now the main panel should have General, Resource Tags, Build Settings, Build Phases, & Build Rules along the top. Select Build Settings, select All. Scroll down to "Apple LLVM 8.0 Language C++" and expand it. Change "C++ Language Dialect" to "C++11 [-std=c++11]".
Build Settings -> Linking-> other linker flags -> add to "-lc++"

gcc options in netbeans 8.0

I'm trying to debug a c++ project (existing code) in Netbeans.
I can run the code fine by hitting the Run button, but debugging isn't working for some reason. I've seen a lot of suggestions telling that the -g flag needs to be added to the gcc compiler options in Netbeans.
From what I understand this used to be done through the *Aditional options" field in the project properties. But this field doesn't exist anymore in Netbeans 8.
Where can I add the -g flag to the gcc compiler options in Netbeans 8?
If it's a normal C++ Application project, then your NetBeans pulldown menu (to the left of the Build Project button - an icon with hammer) should have at least three lines - Debug, Release and Customize. Choose the Debug configuration to build the project, then the -g option will be added automatically.

Cross compiler prefix and path in eclipse

I'm trying to create a C++ project on eclipse. I have installed eclipse-cdt for that.
While creating a project, a pop up window asks for cross compiler prefix and cross compiler path. Could someone please explain what are those and what do I need to add in those fields? Are those fields absolutely necessary to fill?
If you are using a Mac, you can select MacOS GCC instead of Cross GCC. If you are on Windows, you will have to install a C++ compiler. I recommend you install Cygwin, try following the directions here.
https://www3.ntu.edu.sg/home/ehchua/programming/howto/eclipsecpp_howto.html
Once you've installed the C++ compiler, restart Eclipse and try to create the project again. Hope this helps.
In Cross compiler Prefix you need to write 'arm-none-eabi-' and in Cross compiler path you have to select the path for GCC bin folder. You need to install Cygwin GCC for this.
I have found few steps in below link.
https://www3.ntu.edu.sg/home/ehchua/programming/howto/Cygwin_HowTo.html#cygwin
Just in case anybody else is like me and needs more explicit directions as #yeremy is correct in that you have to select MacOSX GCC. It's just that at the point where the OP is, he overshot where he could have made the selection and needs to back up a few windows (about 3) to choose the MacOSX GCC as the Toolchain of choice. Attaching a link below which goes through the steps and which also shows image of window where you can make the selection (figure 11).
Getting Started with C++ for Eclipse - CodeGuru
When Eclipse doesn't detect a toolchain (to be installed separately) it only offers the option "Cross GCC". Don't choose that.
Sites like this tell you that a properly installed toolchain (Cygwin / MinGW) is automatically discovered using the PATH environment variable. This is not the case on my machine.
There's no way to configure a toolchain in Eclipse manually (as of writing) but you can fool Eclipse into finding one without changing your global PATH:
Go to Preferences/C/C++/Build/Environment,
Add a variable PATH and point it to your toolchain path(s), e.g. d:\Mingw\bin;d:\Mingw\msys\1.0\bin. Separate paths with a semicolon.
For newbies just starting out C++ projects in Eclipse:
1 - Click File --> New--> C/C++ Project
2 - In the "Templates for New C/C++ Project" window, Select C++ Managed Build --> Click Next
3 - Provide a project name --> Select "Empty Project" in Project Type section (which is under Executable) and Select "MinGW GCC" in the Toolchains section
4 - Click Finish
Note: Selecting "MinGW GCC" will eliminate the headache of inputting the Cross GCC related prefix and path. Happy C++ learning.
enter image description here

Integrating Clang Within NetBeans?

What are the steps involved in integrating Clang within NetBeans? I would like to also see the Clang error and warning messages from within NetBeans. This will be used mainly for developing in C.
NetBeans 7.2 has supported Clang natively.
Just open up Options Window, switch to C/C++ section, and add a new Tool Collection. Type: /usr/bin in Base Directory, and select "CLang" in the combo box.
I have been using Clang to build my project, and NetBeans works with Clang perfectly.
Here is a link to the bug report for clang support in netbeans at netbeans.org. Track this bug for official netbeans support.
If you have downloaded and installed the C/C++ plug-in for NetBeans 8+ following the instructions on this page:
https://netbeans.org/community/releases/80/cpp-setup-instructions.html
you have a C/C++ item in the upper menu of the Tools > Options panel. 1.) Click it.
2.) Now under the list called "Tool Collection" (on the left) click the left button "Add".
3.) In the window that opens, enter the "/usr/bin" as a base directory.
4.) If you have a CLang compiler installed right the "Tool Collection Family" drop-down menu will show a CLang collection. Choose it.
5.) Click "OK" in the pop-up window, then click "OK" in the "Options" panel/window.
Enjoy.