Help with using Xcode - c++

So, I'm using Xcode to program with C++. I want to access the C++ tool but I'm having this problem.
This is what it looks like when opening a new project. Only for me, I don't have the 'Command Line Utility' option at the end.
alt text http://img.skitch.com/20100305-gsab76ef7bkx5ihwwj94cui39t.jpg
How can I get the 'Command Line Utility' option to be available. I need it to access the C++ tool.
Please and thank you!

If you're on a reasonably current version of Xcode (e.g. 3.2.2) then the selection process is slightly different - you need Application -> Command Line Tool and then select C++ stdc++ from the popup menu.

I have Xcode v3.2
I find the command line utility under File > New Project > (Mac OS X) Application > Command Line Tool (in right pane). When you click on Command Line Tool in right pane you will see a drop down box that lets you select the language you want to use. Mine defaults to C but there is an option for "C++ stdc++".

Related

Qt creator could not parse stddef.h --> incorrect code completion and highlighting

I am developing a QT GUI for my application using QT Creator (4.11.0).
Recently, our IT updated my OS to Ubuntu 20.04 (from 18.04) - maybe the error is related to that.
I have not touched to project in some month but yesterday wanted to continue developing it.
However, within the IDE there are now thousands of errors highlighted at almost every line of my code. (with highlighted I mean that there is this red background and a red dot beside the line number)
On the very top, it says:
Warning: The code model could not parse an included file, which might lead to incorrect code completion and highlighting, for example.
cstddef:50:10: fatal error: 'stddef.h' file not found
...
The errors that are listed in the IDE are very wired like:
type `QMainWindow`is not a direct or virtual base of `MainWindow` (my class is called `MainWindow`)
I'm pretty sure it is not related to my code:
the code compiles and works fine - it is really just the IDE that is highlighting errors at every line of my code.
I have the same code on a Windows Computer and there no errors are listed in the IDE.
even if I start a brand new QT Widget project the errors appear within the template code provided by the QT Creator.
Since the GCC version changed with the update of the OS, I thought maybe I have to define a new KIT but this also did not help.
Is there anything I can do to fix the issue?
Do I have to reinstall the QT Creator?
I know, pictures are not very well-liked but here I think it might help to understand what I mean with "IDE is highlighting errors":
1. First
~/.profile :
CPATH="/usr/include/clang/10/include:$CPATH"
C_INCLUDE_PATH="/usr/include/clang/10/include:$C_INCLUDE_PATH"
CPLUS_INCLUDE_PATH="/usr/include/clang/10/include:$CPLUS_INCLUDE_PATH"
export CPATH
export C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH
maybe /usr/include/clang/10/include see in you file system.
2. Second
Logout / login.
3. Third
Specifying Build Settings (Projects -> Build -> in every config build) in Build Environment section: [unset] CPATH, C_INCLUDE_PATH and CPLUS_INCLUDE_PATH
or [edit] replace this variable with the necessary values
I fixed this issue by sudo apt install clang-8.
Source: https://bugs.launchpad.net/ubuntu/+source/qtcreator/+bug/1890434

oh-my-fish `omf: command not found` in WebStorm terminal emulator

I am using WebStorm 2017.1.3 on Fedora 25.
I have fish set up as my default shell and installed oh-my-fish so in
Terminal I see my git branch and other information by default. omf update runs as expected.
In the WebStorm terminal emulator I still get fish, but not omf:
user#host ~> omf
fish: omf: command not found...
I'm a noob fish and omf user, can anyone help?
Thanks.
I have fish set up as my default shell and installed oh-my-fish so in Terminal I see my git branch and other information by default.
Note that you don't need omf for this. Fish ships a number of prompts that include vcs information. You can pick one with fish_config or add the __fish_vcs_prompt function to your fish_prompt.
In the WebStorm terminal emulator I still get fish, but not omf:
user#host ~> omf
fish: omf: command not found...
The "omf" function is stored in a file named "omf.fish" in a directory in $fish_function_path. This means that directory isn't included there.
The way omf works in a reasonably current (> 2.3.0) fish is that it has a bootstrap file (~/.config/fish/conf.d/omf.fish) that then sources the rest. It seems this isn't run.
I'd suggest you compare the values of $fish_function_path, $OMF_PATH and possibly $XDG_DATA_HOME in webstorm and outside of it.
An answer was given here: IntelliJ's embedded terminal does not load fish functions. I.e, add some lines of code to the app for the time being (until Jetbrains makes a fix).
I fixed this by going to Settings | Terminal then turning off Shell integration.
This allowed me to run omf and also have the bobthefish theme work with powerline/nerd fonts (after updating the terminal font at Settings | Editor | Color Scheme | Font Console)
I was using phpStorm 2017.3.4 but I assume this will also work in any IntelliJ embedded terminal.

GDB on eclipse debug mode can't find stdlib/rand.c

I am trying to put the gdb to run with eclipse cdt on ubuntu to start debugging some simple programs. So I did the steps I reckon as necessary to get it running:
1. Create an executable project
2. Compile
3. Run
4. Create the file .gdbinit and place it on the main project folder
5. Set some of the debugger configuration:
5. I also tried to find a .gdbinit file that would look some like this:
set schedule-multiple
dir ~/gcc_build/4.7.2/build/gcc
dir ~/gcc_build/4.7.2/gcc
dir ~/gcc_build/4.7.2/gcc/cp
dir ~/gcc_build/4.7.2/gcc/lto
source ~/gcc_build/4.7.2/build/gcc/gdbinit.in
But I didn't find anything similar in my computer, even after doing a:
# find / -name .gdbinit
So, my file .gdbinit end up with the simple content - yes only that:
set new-console on
Then I clicked on Apply and Debug:
The gdb starts working nicely as expected. I press the button "step over / F6" and the debugger goes jumping through the code step by step. Until the point it reaches the command rand() and the gdb hangs with the message:
Can't find a source file at "/build/buildd/eglibc-2.19/stdlib/rand.c"
Locate the file or edit the source lookup path to include its location.
Thus I also tried unsuccessfully to find the rand.c to update this path to include its location:
# find / -name rand.c
# find / -name stdlib
After the error message from GDB complaining that rand.c is missing, then I tried to keep stepping... since then the stepping mode is disable when I restart the debug:
Is this problem happening because some setting for my file .gdbinit is missing? Or some how GDB is not able to find the rand.c from stdlib from c99? When I compile and run the program it runs nicely. Only when I try to launch the debugger is when GDB crashes.
Update: I got the missing rand.c problem after running the commands:
# apt-get install libc6-dbg
# apt-get source libc6
But now a different error appears:
Can't find a source file at "/build/buildd/eglibc-2.19/csu/libc-start.c"
Locate the file or edit the source lookup path to include its location.
Should I also install that library for gdb?
All suggestions are highly appreciated.
From what I saw on your description... looking to the 4th and 5th image you posted, you did right all the required steps.
However, it seems to me that your GDB is attached to several projects. That means that unless you really need that, I would strongly advise you to select all project that you are not currently debugging and delete them from the debugger mode. So, my suggestion is that after you have done all the steps you did so far, then go on:
Debug Configurations > C/C++ Applications: (drop down it)
... then click on each project you are not compiling, with right button from the mouse select "delete" - but don't worry, it will not delete your project, but only the attachment of that project to your debugger mode.
Then restart the eclipse. When you again try to run in the debugger mode, everything will run much smoother than before.
Step1:
Go to https://www.gnu.org/software/libc/ to download glibc.
Step2:
unzip it locally and whenever the eclipse prompts "Can't find ... xxx.c", just load the file into eclipse. It will work.

How to disable Eclipse CDT code formatter for a code block

The CDT code formatter has a pretty decent selection of options, but it doesn't seem to have to a feature that allows one to tell it to ignore a block of code. This feature exists in the Java code formatter:
// #formatter:off
... // code that should not be formatted
// #formatter:on
Does this feature exist and I just don't know about it, or does anyone know of any decent work-arounds?
In my particular case, I'm trying to define data structures (enum types and arrays of strings) that I want to have specific layouts.
Use Astyle (Artistic Style) formatter, it's far superior to the Eclipse CDT built-in formatter and has the feature you require:
http://astyle.sourceforge.net/astyle.html#_Disable_Formatting
Example:
#include <iostream>
int main(int argc, char** argv)
{
// *INDENT-OFF*
std::cout<<"hello world"<<'\n';
// *INDENT-ON*
}
Formatting this using astyle won't indent the code between // INDENT-OFF and // INDENT-ON but it will also disable any other formatting features astyle does, like the spacing of the instructions in this case.
I use it myself configured as an external tool.
The only problem, external tools don't have hotkeys, but there is one hotkey to "Run Last Launched External Tool", and if you only use one external tool it works the same.
More details about the configuration (linux):
Astyle:
You can get it easily from your distribution repositories or via the official site.
To setup a configuration file with the formatting settings:
http://astyle.sourceforge.net/astyle.html#_Options_File
I use the home folder variant, just create a .astylerc in your $HOME, mine contains:
--suffix=none
--style=allman
--indent=tab=4
--max-code-length=70
--close-templates
--keep-one-line-blocks
--break-elseifs
--break-closing-brackets
--align-reference=type
--align-pointer=type
--indent-classes
--indent-modifiers
--indent-switches
--indent-cases
--indent-labels
--indent-col1-comments
--min-conditional-indent=0
--pad-oper
--pad-header
--unpad-paren
Eclipse:
"Run" menu --> External tools --> External tools Configurations... Add a new "Program" and in the configuration window:
Location: /usr/bin/astyle (use whereis or locate to check this)
Working Directory: ${project_loc}
Arguments: ${selected_resource_loc}
In the same window, refresh tab:
Tick Refresh resources upon completion.
Tick "The selected resource"
Same window, common tab:
Display in favorites menu, Tick "External tools"
Yes, you can do it since CDT supports this feature starting from version 9.7. The behavior is exactly the same of JDT.
If you are using OS X or Linux (I haven't checked Windows, but it may be supported), you can use clang-format and CppStyle instead.
clang-format is a formatter utility which is provided with Clang, and it supports on/off comments // clang-format on and // clang-format off in C/C++/ObjC code. An introduction to build Clang and its utility tools can be found here.
http://clang.llvm.org/get_started.html
You do not need to install whole Clang and LLVM files on your system. Because clang-format is a standalone program which works without Clang. The on/off comments are not supported in old versions, so please use ver 3.7 (available from SVN as of Feb 2015).
CppStyle is an Eclipse plugin which enables us to use clang-format from Eclipse CDT.
https://github.com/wangzw/cppstyle
FYI. Here is the same feature request in the CDT Bugzilla. The functionality might be officially supported in future, but using clang-format or Astyle seems to be a better solution at the moment. https://bugs.eclipse.org/bugs/show_bug.cgi?id=453926
I guess I could stick these in a file with an extension ignored by the formatter and include this file where appropriate. I tried this out and it works - the data structure gets picked up the indexer (i.e. autocomplete works). Still, it would be nice to have an equivalent to the Java "#formatter:..." syntax.
As far as I know the answer is simply no, such a feature does not exist. You might be able to implement such a feature using the SDK though. Beware that in my experience the documentation is very incomplete and it's very hard to find an Eclipse developer who would be willing to help you fill in the holes. But since the feature exists in the Java formatter and it is an open source product, perhaps you could port over the logic to the C++ formatter.
You could also avoid formatting the whole file, and instead format only by selection.

Can i go to the error after executing make in VIM?

Can i go to the line of error , while compiling a C or C++ project ? Usually by executing make , and parse the error string , and go to the specific file , and the line with errors.
Is there already an usable plugin ?
Yeah this is already buit into vim. After typing :make type :cwindow to bring up the error list. You can then navigate to the errors using this window.
You can as well after :mak or :make do :cope to open the window with compiler output and once you are done :clo to close it.
Use :cn and :cp for jumping to next and previous error or when you are in the window go to line that has the error with file name, line & column and press enter to jump there.
IIRC, this functionality is built into vim. A quick google search revealed this useful link. This describes vim's features for navigating the errors after a make.