66 comments

[ 3.1 ms ] story [ 116 ms ] thread
I'd recommend using clangd together with the vscode-clangd extension instead of VSCode's "official" C/C++ extension. Properly set up with a compile_commands.json and its pretty much better than any C/C++ IDE I've ever used.
ccls works even better than clangd, in my experience.
Interesting. I have used VSCode on Mac for C++ but it has been a royal pain in the ass recently with lldb-mi issues related to Catalina.

If you don't mind sharing I am very interested in your setup.

Sure!

I use CMake for all my projects, and passing "-D CMAKE_EXPORT_COMPILE_COMMANDS=ON" generates the compile_commands.json for clangd. I create a symlink to it in the main project folder so clangd can find it.

Clangd embeds clang-format and clang-tidy, so given appropriate configuration files formatting in VSCode just works with no extra extensions but vscode-clangd.

For debugging, I use CodeLLDB. Haven't had any problems with it so far, everything seems to work fine. Debug console works etc.

Could you explain what is better? And how to properly set up compile_commands.json? It seems I struggled with getting `make` to work with VScode.
Debugging for one. You have to use a C++ debugger alongside Rust, and the lldb debugger is immensely superior (especially where structs are concerned in locals/watch).

I strongly recommend you have a look at vcpkg for getting tooling such as make and gcc installed.

I would like to recommend the official C++ extension + CMake Tools. This combination provides great IDE-like experiences.
Is it that hard for addons to implement proper settings GUI dialogs in vscode? Editing json files by hand is step backwards, especially when this comes from the company which also produces (real) Visual Studio.
What settings are you referring to? VSCode's settings (both main and extensions) have a GUI view. The compile_commands.json is always generated and not meant to be edited at all.
Settings of particular extensions, e.g. Golang's. When something is explained (e.g how to add build targets) it always goes to editing some json files.
The settings GUI in VS Code was only added in the past year or so. So it's likely that a lot of documentation hasn't been updated to mention this.

Even so, I prefer editing the JSON files directly. I can easily see what's changed from the default, add comments, and make groups of settings.

what advantages does vscode add for c++ development over current IDEs and editors?
I guess if you're used to vscode there is that.
It's simple, light weight, a lot of cool extensions. I use vscode for developing nodejs, python, ffmpeg, Qt, frontend...it's my all in one IDE.
How exactly it is lightweight when it carries a copy of Chrome browser in the background? Jut at idle with no files opened it uses 600 Mb of memory. PS: it is a nice software which I also use extensively, but Electron is an abomination, Flash of 21 century.
It's not "lightweight" at all. lol
Compared to say, intellij; it just feels lightweight. It's nicely optimized at least.
JetBrains IDEs are all by far the most clunky of all the choices.
You clearly haven't used Eclipse (and I say this as someone who chooses to use Eclipse).
true... sorry I forgot that monster still exists
They're also leaps and bounds better as IDEs than VSCode. I'd gladly exchange some "clunky"ness for a better experience and more features driven by a proper GUI.
I use both Visual Studiio and JetBrains Rider at work. Rider has much less loading time and way fewer micro/macro stutters.
Just opened it up on my machine (2019 Macbook Pro)- 65MB with no files opened. No idea how you're getting to almost 10x that.

Edit: My bad, apparently I didn't count all processes.

You have to take into account the helper and renderer processes. A freshly launched instance takes around 250 MB on my system. It consumes more as you open files that trigger lazy loading of additional extensions. Still less than other IDEs, though.
Interesting. I also just opened it on my MacBook Pro it uses ~300MB of memory with 5 extensions. emacs with about half a gazillion packages uses 91MB.
10 minutes ago, I downloaded the latest VSCode 1.43 and installed it on a fresh macOS 10.15.3.

Launching it with no files open, the total private+shared memory adds up to ~300 MB. Screenshot of macOS Activity Monitor:

https://imgur.com/a/xDdzDRr

This memory usage is roughly the same on Windows 10 Task Manager:

https://imgur.com/a/xWkdoN1

In contrast, the so-called "heavier" classic Visual Studio 2019 v16.5 (devenv.exe) with no files open, Task Manager stats shows it using less than ~200 MB.

I think some folks get the impression VSCode is "lightweight" because the GUI/UI is lightweight. VSCode is less "busy" looking... less menu options, no ribbon with icons, less multi-panels of properties, etc. VSCode's GUI looks more like a bare-bones "text editor" than an IDE.

It's lightweight when compared to other IDEs like Visual Studio, IntelliJ or Xcode.

How they do it while using Electron? No idea.

lightweight maybe is not correct. maybe simple is more correct.
Can you debug C++ with line breaks in VS Code?
The deceptive answer is probably "Yes" to whatever such incarnation of that question you ask. But as always when it comes to VSCode, it's buggy, half-configured and most of the config is weirdly hidden inside json-schema driven JSON config files that may or may not work. So much so that for me it effectively becomes a "No" answer.

That's been my experience with watching stubborn fellow co-workers struggling with it while doing python development. On paper, it has all the features and whistles of course, so therefore it's the "best IDE".

Code completion, type-annotation, debugging, virtualenv, built-in linting, docker support, etc. But then when you use them, it's a virtual catastrophe of configs, random "does it work, no, try the config again, does it work now? Yes No?" And so it continues, for an hour. Meanwhile, a python IDE like PyCharm just works without hassle.

How do you develop ffmpeg what do you mean ? What kind of projects can one create ? Do you mind sharing resources ?

You got me interested ^^

I develop some filters to ffmpeg or read ffmpeg codes in vscode. Build by makefile and then debug in ffmpeg.
How does it compare with Clion, the IDE from jetbrains.
There are some extensions Clion doesn't have...I install many extension in vscode.
Qtcreator is leaps and bounds ahead of vs
Yeah, also the only IDE that can open and index Chromium sources(about 40k files).
A few weeks ago I was reaching for VScode + Qt because I normally do a bunch of small one-offs. My go-to is mostly command line (vim and shell scripts for building or Makefiles or eventually cmake if things get "heavy")--which means I'm very excited about avoiding qmake in favor of cmake. I find most IDEs unbearably slow and heavy, but I really like Visual Studio's debugger (with multiple languages).

I hear great things about QtCreator, but for me it's more about not wanting to invest in yet another large application for things I don't do every day.

Thanks for this, I'm sure many would give it a try and will like the idea of having the possiblity and easier selection when working with their favorite IDE or editor when working with Qt.

Having said that, I will never leave QtCreator for VS Code, not that is not good, but QtCreator feels much solid and integrated than any other IDE when working with Qt/C++ or many C/C++ code bases out there, in matter of fact, QtCreator is my go to when doing c/c++.

I've tried CLion but I don't think will use that either.

Need to mention is so damn light ?

You're not the first person to mention QtCreator for c/c++ projects ( not even using QT ). Can you elaborate about what you like about QtCreator over other c/c++ IDEs?
I use Visual Studio 2017 to develop a Qt application on Windows. I use Qt Creator (QtC) for same app on macOS. I love Qt, am delighted to have converted from Win32.

Sorry but VS still feels as solid as a tank, Qt Creator is less responsive to my needs.

- 'asserts' in QtC bring the debug session to a grinding halt. I can't step over like I can in VS.

- Where can I define macros in QtC?

- In debug mode, QtC is unable to display certain types of variables, way too often.

- I have fiddled for days with the .PRO file, read all the StackOveflow posts, and I still can't suppress reams of pedantic warnings.

- QtC just gives the impression of a rudimentary attempt at VS, like things are about to fall apart at any moment. To a programmer accustomed to VS, there always seems to be something missing, and I don't mean just different keyboard shortcuts. QtC has a long way to go.

Still, it's better than a text editor and the command line.

Fun, I have exactly the opposite experience re. VS and Qt Creator - VS sometimes takes, like 15 minutes to start a debug session on a large project while QtC can get to work in the same time that it would take gdb to start. And that's without counting the clang-based code model, all the niceties under the locator (ctrl-k), etc etc

> Where can I define macros in QtC?

the IDE is imho not the place to do that. Just use CMake and target_compile_definitions(my_target PRIVATE MY_MACRO=123)

> - In debug mode, QtC is unable to display certain types of variables, way too often.

very strange, but then I mostly use it on Linux with gdb / lldb, maybe the cdb integration is less good.

> - I have fiddled for days with the .PRO file, read all the StackOveflow posts, and I still can't suppress reams of pedantic warnings

If CONFIG += warn_off in your .pro (switch to cmake !!!) does not work please file bugs !

Not sure if this applies to Qt, but VS2019/netcore has made tremendous strides with its tiered compilation.
Is there a reason I wouldn't just use creator? Does VS offer me something creator can not?
Tabs
Qt Creator has vertical tabs ("Opened documents" panel) which is way superior as soon as you have more than 3 files open. It's also pretty useless since you can just <ctrl-k> <first few letters> <enter> or <ctrl-tab> to switch
It has a better extension ecosystem by a wide, wide margin. Some of the benefits that can bring from my personal experience:

- Using the same editor setup for tons of different environments (Python, C/C++, Rust, JavaScript, TypeScript, Java, Go, and more are all very well supported)

- The VS Code remote editing extensions are fantastic: https://code.visualstudio.com/docs/remote/remote-overview

- There are live collaboration extensions that let you pair program with other devs over the internet, with really good responsiveness

- The remote extension also lets you specify a dockerfile/image ref + plugin configuration in your repository, which can then be used for your editing. This effectively gives you transparent, Git-based, immutable development environments. This can be a big productivity boost.

I've also found it pretty easy for most people to pick up and use, and it's also fairly lightweight and reasonable IME.

I love Qt Creator, but the lack of tabs drives me nuts. The interface is so unfamiliar that I just can't use it. I use it to debug, to build interfaces, to compile, etc... but to code, I just use Sublime/VS Code/Atom/whatever.
That's funny because I prefer "Open Documents" dock in QtCreator to the tabs. It's hard for me to switch between files because I can just see 7-8 tabs without scrolling and in the dock I might have 20 files with longer names.
Is anyone here using gitlab with a runner to build QT applications upon commit? I've got a friend who needs this and he is only using QTCreator but it seems like building inside a docker container should be possible. I guess I'm asking: can all the things discussed here be done from command line instead of inside the editor and if so, how do you determine those commands?
Sure, you don't need an IDE to build a Qt app.

If you set it up using cmake, it's like any other app: cmake, make, done. (cmake has support for handling the Qt specific bits for you)

If you're using Qt's qmake, which is likely if they just started with QtCreator, you call qmake and then make to build.

In both cases I'd refer you to Qt's documentation for details, but QtCreators project configuration UI and build log also shows you which commands it is running.

I have a project that has this same workflow, in my gitlab-ci file I just run qmake followed by make. I have a custom container which contains the QT library and build tools.
Are any of you available for a consulting project? If so, can you email me at the email in my profile?
I've led adoption on that exact setup at work. You can definitely do it, but I have nothing but bad things to say about Qmake. It's poorly documented, inscrutable, and a huge PITA. Switch to any other build system if you can.

That said, automating the builds in GitLab CI was worth it 1000x over.

If you’re fighting qmake there is a very good chance you’re fighting the wrong problem. Is your build a complicated mess? (It shouldn’t be) Do you have a complicated multi platform mess (it shouldn’t be complicated)

I would be happy to take a look at your build.

Off the top of my head:

- qmake doesn't support true dependencies between subprojects (ie, if I ask it to build a/b/c, it can't know that a/b/c depends on d/e/f)

- qmake's support for integrating additional compilers is inscrutable and again, has terrible issues with parallelism and dependencies

- the way it is backed by make is prone to incremental build issues

For point 1, it can if you want it to. https://wiki.qt.io/SUBDIRS_-_handling_dependencies#Defining_...

I have qt kits to build for 4 different platforms and 3 different build toolchains. It was very easy to set up, and flipping between kits either in creator or in a terminal takes mere seconds.

I have never experienced your 3rd point.

That allows you to support _some_ dependency ordering from the top level, but not internally. It is very coarse, and also suffers from “recursive Makefile” issues. It’s also less ergonomic: a developer can’t go into a specific sub folder and build ONLY that sub folder and its dependencies. If you change a library, it also can't reliably tell you which other binaries are its dependents. You have to let Make walk the full project tree.

By “additional compilers,” I mean adding additional metacompilers, other languages, and so on. There is QMAKE_EXTRA_COMPILERS, but I can’t figure out how to get it to properly integrate with the dependency graph for the life of me.

Have you ever had to resort to “make distclean” to get a clean compile?

On your first point I respectfully disagree. The functionality does exactly what you claim it doesn’t do. You are mistaken on every point in your first paragraph.

For your second point: https://ortogonal.github.io/qmake-extra-compiler/ I have never used this but it looks straightforward enough.

I have never had to use make distclean. I use make clean && qmake && make sometimes.

> It’s also less ergonomic: a developer can’t go into a specific sub folder and build ONLY that sub folder and its dependencies

I'm not a fan of qmake but this works just fine with it.

The dependencies is the trick.

Given I have this layout:

    bin/bin.pro # specify bin/bar/ as subfolder
    bin/bar/bar.c
    bin/bar/bah.h
    bin/bar/bar.pro
    lib/lib.pro # specify lib/foo/ as subfolder
    lib/foo/foo.c
    lib/foo/foo.h
    lib/foo/foo.pro
    project.pro # specify bin/ and lib/ as subfolders
And I have a fresh checkout, how do I compile "bin/bar" and all of its dependencies automatically? I want to run ONLY "bin/bar". I don't want to compile the entire repo. I don't want to have to investigate "bin/bar" and learn all of its transitive dependencies. I just want to run "bin/bar".

Honest to god, I have wanted this for over a year and it does not seem possible.