Getting clang++5.0 to work on Xcode - c++

Clang 5 is finally out there and I have eagerly downloaded it and tried the coroutine example. Everything works nicely from command line and I am very happy about it.
Now, I would like Xcode to use clang5.0 to compile my code, so that I can play with coroutines and other experimental C++20 features with my favorite editor. Is it possible to do such a thing?
I have seen this question and, full of hope, I followed the instructions to replace clang and libclang within the Xcode package.
Xcode starts properly, however when I try to compile an hello world I get a lengthy linker error message that ends with Cannot specify -o when generating multiple output fiels.
Am I doing something wrong? Is there any guides out there to get this to work? Otherwise, I guess I'll just have to change IDE. Sigh.

Related

Using g++ and ./a.out

Hello everyone I have finally decided to learn to code, even if it is just a hobby, I once picked it up years ago and I am gong through the tutorials on codeacademy, I have a question for everyone.
Tonight I downloaded Codeblocks with Ming compiler, the programs work fine, the ones I have tried to rewrite from memory from my lessons, but I am missing something that became second nature during my lessongs. After writing the code required for the challenge, I would go into a folder with the extension .cpp and add the command g++ temperature.cpp(for example) -o temperature and then once the a.out file was created I would go into that and do the ./temperature command to execute the program.
I like being able to manually compile and than executre my code, and would like to be able to do this in codeblocks. I know it may sound stupid, and I know Codeblocks does it for me, but is there any way, I can do it for myself? Is there any way I can write my code and have the terminal on the right side of the screen like codeacademy has it?
Or should I just forgot about the g++ and ./ commands? I figure that I can do it throug the command prompt but that would require getting to the folder etc, and have not yet fully familiarized myself with the command prompt.
Thank you in advance for the help.
I first commented, then I decided to make it a full answer, since I kind of answered the heart of the question in the comments by accident anyway.
Yes, you can absolutely do this yourself. Using an IDE (Integrated Development Environment) like Codeblocks will make things easier for you, but there is no harm in learning how to do it under the hood if that interests you--especially if you're doing this for a hobby and not a work situation with time constraints.
To understand what g++ is fully capable of, I recommend consulting the official documentation. That will explain how to properly use it better than me and probably anyone else could.
While you're at it, I would also recommend learning how to use make if your platform supports it. It is a tool that can make compiling easier than working with the compiler directly, but offers more control than your IDE might (though this depends on the IDE).
You mentioned that you used the Ming compiler for Codeblocks, so I'm assuming that you're on Windows. To use the g++ command here, you'll have to
Add it to path, in order to make the g++ commands available for you throughout the system. This video explains adding the ming compiler to the path pretty well.
Call the command (from the command prompt, or some other kind of terminal)
You will have to get just the basic commands down for the command prompt, but it's not that daunting. cd to change directory and dir to list directory, and navigate to your project directory in codeblocks.
Finally, keep in mind that because you're on windows, when you compile with g++ you'll get an .exe file. .out files are produced when you compile on linux. If you want to get a linux shell on windows, I'd recommend looking into either Cygwin or WSL.
IDEs make compiling and executing much more convenient, but it's not a bad idea to learn how it all works through the command line. Best of luck!

Syntax highlighting and code inspection in CLion stops working after including anything from standard library

The problem started happening after upgrading GCC to version 10 on Ubuntu 20.04.Basically my code gets highlighted and inspected fine until I include a standard library header (string for example). Sometimes when I remove the include line the highlighting comes back and sometimes it comes back only if I restart CLion after removing the line. The code compiles fine. I already tried reinstalling GCC, CLion and whole Ubuntu and the problem is exactly the same. The problem is not consistent for all the headers because cstdint works fine and doesn't break anything but string, map and iostream do. I don't have any external plugins, it's a totally fresh install of the newest CLion and Ubuntu. Going back to GCC-9 fixes the problem, but GCC-10 just doesn't seem to work.
Trouble in CLion happens sometimes when the software detects that it uses too much memory. The only solution that I know is to close some files and reopen the one on which you want the functionnality.

How to see code coverage of tests in Xcode 10 for C++ project

I have a C++ Xcode project on Mac, and I'd like to see how much code coverage my tests have. If I were building on linux, I would pass a few extra flags to GCC and then use gcov.
What I'm looking for is a way to do something similar on Mac, either through Xcode or through the command line.
This link describes how to get the code coverage tools that Xcode has built in to work, but unfortunately those seem to only work for ObjC or Swift. All the other articles I've found have been similarly unhelpful (either very out of date or only for Swift/ObjC).
I'm not sure how to get this running through the command line, since I'm not even sure what command(s) Xcode uses to build my project (I assume xcodebuild, but I'm not sure what arguments).
I'm fine with doing this either through the command line or through Xcode, whichever is easier.
Any help would be appreciated, please let me know if you need any more details.
Details:
I am using Xcode Version 10.1 (10B61).

How to configure qt creator to show C++ code rather than disassembler?

Yesterday I had done a lot of things like updating GCC, Clang and reinstalling Qt Creator.Today when debugging my code step by step, the debugger was showing the disassembley rather than the C++ code I wrote. Pressing F10 or F11, the debugger was moving into assembly code not the .cpp nor .h files I wrote. F11 can only go into the library files but never into the files I wrote.
The arrow appeared in disassembler:
Rather than in main.cpp:
How can I configure Qt Creator such that the debugging arrow tracks each line in the C++ code?
For others who also had this problem but none of the solutions above worked (like me), I found out that the issue for me was simply happening because my project was inside of a directory with special characters (/home/fabio/criação/project) the criação folder seems to have caused the problem. After I changed to /home/fabio/Desktop/project it stop happening.
I ran into a very similar problem debugging code built with the clang toolset in qtcreator, and this answer fixed me up:
gdb doesn't find source files compiled by clang++
You can quickly check if that solution will work for you by navigating to the root of your solution in a shell window and then invoking qtcreator from there...set a break point in main() and try debugging - if it stops and shows source in main.cpp, it's quite likely this is the problem.
If that does work for you, there are probably several better ways to implement the permanent solution suggested by https://stackoverflow.com/users/1632219/rene, but the method that worked for me was to modify my qmake mkspec file for the clang toolset. On my system, it lives in /usr/local/Trolltech/Qt-4.8.5/mkspecs/common/clang.conf, so all I had to do was put a clang invoker script with 'clang++ "$#"' in ~/bin/clang-compile and then set QMAKE_CXX in the mkspec to clang-compile. With that change, when the clang toolset is selected, qmake builds make files that use clang-compile instead of clang++ and then debugging works everywhere.
At last, I found that it was Clang that had caused this problem. After changed the kit back to using gcc, it just worked fine. But not sure whether it's Clang's fault or that the script Qt produced for compiling has any problem. Anyway just put the answer here in case anyone else who might encounter the same situation.
Goto "Help->About Plugins" and check the "ClangCodeModel" and restart QT.
There is a bug in version Qt 5.6.1 (MSVC 2013, 32 bit) QT Creator4.0.3.
In debug mode put your breakpoint. Then hit the step into(F11) it will start debugging now. To go to your code hit the step-over(F10) until you come to the code page.
I have searched about this problem but nothing worked. Some solution, i didn't get.
This is very annoying issue.
Maybe it will work if you clean, qmake and rebuild.I solved this problem by using this method.

How do you run programs through TextWrangler?

I have just started to get experiment with C++ on my MacBook Pro, and am very new to it all. Through research, a few different people have suggested to use TextWrangler for writing the code. I have put together some of the code that the beginning of a tutorial has given me, but I am now unsure how to run it through TextWrangler. I know that you are supposed to compile it first, but that is mostly where I'm stuck. I have downloaded Xcode so I have gcc, but I don't know where to go from there. And after I have compiled it, is there a simple way to run the file? Like I said, I am very new to all of this and may be looking at it in the wrong way.
TextWrangler is only a text editor, you still need a compiler to compile your code and then you need to run your code.
Xcode (which is an IDE) does all that for you so the confusion is understandable.
for now opening a terminal and doing g++ filename.cpp to compile and ./a.out to run your program will get you going. But you really have to learn to use a IDE or how to write a makefile.