
C++ Ecosystem: Compilers, IDEs, Tools, Testing - joebaf
https://www.bfilipek.com/2019/10/cppecosystem.html
======
cmrdporcupine
CLion is an amazing tool -- I've purchased licenses for my personal self in
the past, but my employer pays for it these days.

My problem is they've done a terrible job of making it scale up to large code
bases. I work on the chromium tree -- CLion is completely useless on it. I
have a dual 24-core xeon with 128GB of RAM and SSD and I've given it a
wackload of memory, and it becomes completely inoperable, freezing all over
the place.

Awful because I have such muscle memory for the JetBrains tools, and such a
fondness for them.

I've gone back to using Emacs, but now with Eclim. I just couldn't get into
VSCode.

~~~
AnthonBerg
Interesting. Chromium seems to be huge indeed. I googled statistics: 3+
million lines of code? Is that about right? (Not that LOC is a great universal
metric of everything, but it's something.)

For comparison: I work on something a magnitude smaller:
[https://github.com/CleverRaven/Cataclysm-
DDA/](https://github.com/CleverRaven/Cataclysm-DDA/) ... about ~360,000 LOC.
CLion is pretty great for that.

I'm curious, have the VM garbage collection and allocation settings been
adjusted? In other words, not just the memory limits but also switching to a
different garbage collector and the GC control mechanisms adjusted? I've been
reading up on the collectors. As far as I can tell the G1 collector is
strongly indicated when you go above a 4 or 8GB heap. It then has a number of
settings to adjust. I got really good and smooth performance out of it - few
and short enough pauses that I was at peace with CLion - but seemingly I set
the garbage collection to be "too continuous" which caused constant CPU usage
when I used that profile in Pycharm on a Python project. Had to switch Pycharm
back to a more, uh, classical GC setup. (I didn't reconfigure to rein it back
in as it was unnecessary in that context. I'm sure it's possible.) The JVM and
the GC are a rather interesting beast.

Just curious :)

~~~
cmrdporcupine
Yes it's a massive project. I've attempted all sorts of GC tuning. I'm not
convinced it's all GC issues; I think whatever data structures or algorithms
they are using for their semantic tree must not scale well to extremely large
data sets. It also doesn't seem to be terribly friendly to high concurrency.
Having lots of cores doesn't really help.

CLion seems to struggle in particular with the presence of the out / generated
source directories in Chromium. Even when asked not to index (exclude), the
mere presence of the directory seems to bog it down.

The tool also needs to have a more flexible notion of source roots/include
roots. I should be able to notify it that a directory is an #include root
without having it try to index every .c file etc. underneath there. I should
be able to select a group of directories and say "these have headers, but
they're relative to path X, rather than themselves" etc.

~~~
AnthonBerg
Many thanks! I assumed that GC tuning had indeed been attempted.

------
Iv
I had to use Qt as the UI lib for a project, it made me discover that
QtCreator was actually not a Qt-only tool but a very good lightweight and
generic C++ IDE.

That's my choice now. I need something that can navigate easily in a code
base, I don't really like learning all the oddities around emacs and vim (even
though I am a bit competent at vim) and I don't see what is so bad in using a
mouse.

At first I thought annoying to have to manually edit the .includes and .config
to add the includes and the macro I needed in our complex, hard-to-parse CMake
based project, but now I really enjoy the freedom it gives.

------
alexhutcheson
The worst thing about C++ is the endless sequences of choices you need to make
about tooling before you even write a line of code. This is actually what made
me switch to Go for personal projects - I'm a professional C++ programmer, but
setting up a development environment required so many choices and so much
futzing with various tools that I would spend all my energy getting set up and
never make progress on the projects themselves.

Go, Rust, and even Java are all way better in this department - the tools are
standard enough that you only have to make a choice if you are doing something
less common. I would love a Dropwizard-like bundle that just gives me a pre-
set-up config with everything I need to write a C++ CLI app or daemon.

~~~
codesushi42
Even Java? Java's tooling is top notch.

IDE is awesome. Debugging tools are rawsome. Build tools can be... Well you've
got choices. Workspace setup is easy

~~~
hermitdev
Ive spent a good part of my 20+ year career wrangling c++ dependencies, and
it's hard. MS has introduced vcpkg, which should make things better, closer to
a pip or npm style package manner, but I haven't used it, so I have no idea
how well it works.

~~~
batty_alex
> ...wrangling c++ dependencies

Yep, I think this is my main gripe with C++ on Windows right now. vcpkg is
meant to work with CMake or Visual Studio, but you still have to manually tell
it where your toolchain file is - which means it's additional work for the
rest of your team. In Visual Studio, it's seamless.

On Windows, it's gotten to the point where I try to build dependencies as part
of the build chain and hope the tooling is smart enough to not rebuild them a
million times. Would be really nice if Windows 10X (or whatever) could come
with a package manager or integrate vcpkg.

------
pjmlp
C++ Builder + VCL keeps being the only development environment where RAD and
C++ really go hand-in-hand.

Sadly thanks to their management mistakes and the trend of wanting everything
for free, only a select few know how it actually feels in practice.

C++/CX + XAML came close to it, but got replaced by C++/WinRT, which is still
catching up to C++/CX tooling.

~~~
babuskov
What about Qt? Doesn't it have something similar?

As a cross-platform C++ Builder replacement, I have been using wxFormBuilder
and wxWidgets in the past. There are some manual steps, but it let's you build
a GUI quickly, hook up event handlers and then write implementation code in a
derived class, so that stuff generated by GUI editor doesn't rewrite your
code.

~~~
pjmlp
Not 100% alike, because it depends on QML/JavaScript and lacks the eco-system
of third party components.

Thanks for the wxFormBuilder and wxWidgets reference, I always saw them as a
MFC wannabe and don't have any experience with them.

~~~
gnud
You can still use QWidgets, which is more similar to VCL.

There are third-party components (for example the open-source Qwt [0]), but
probably fewer than you find for VCL :)

0: [https://qwt.sourceforge.io/](https://qwt.sourceforge.io/)

~~~
pjmlp
QWidgets are stuck in desktop deployment scenarios, with QML taking front row
for everthing else, something that they plan to change with Qt 6, which
remains to be seen in what form it will be done.

Qwt is not the same as the commercial support from component oriented
companies, including the UI/UX care of some components.

------
lordnacho
Gotta have Valgrind suite in there somewhere. Useful to find use-after-free
and loads of other issues. Plus cachegrind and the rest of the suite.

~~~
mehrdadn
Do people use Valgrind much in C++? I've never had to. I feel like the only
time I'd need it is if I'm writing "C++" code that is really just glorified C.

~~~
tomnj
Due to the memory unsafety of C++, memory debuggers are absolutely used,
including valgrind's memcheck and the Google sanitizers. Memory leaks and
double frees are easier to avoid in C++ than C even without tooling, but use-
after-free (for example) is absolutely a problem. And "modern" C++ won't
necessarily help you here: even heard of string_view, span, or ranges? Memory
debuggers are also often used in conjunction with fuzzing to track down bugs
that the compiler may not tell you about.

------
OlivierLi
No mention of any LanguageServer implementation?

I highly recommend rtags (even if it's not stricly LSP)

[https://github.com/Andersbakken/rtags](https://github.com/Andersbakken/rtags)

~~~
xvilka
For the C++ using ccls[1] is way better.

[1] [https://github.com/MaskRay/ccls](https://github.com/MaskRay/ccls)

~~~
lorenzhs
clangd is really good these days (clangd-9), I suggest you give it a try. It's
incredibly easy to set up if your distribution packages it. I'm using it with
Emacs' lsp-mode, it's great.

------
29athrowaway
A few more:

\- compilers: Intel compiler

\- IDEs: SlickEdit, GNOME Builder, KDevelop, Eclipse, Netbeans

\- Build systems: Bazel, Meson

\- Static analysis: Klocwork, Coverity Scan

\- Fuzzer: American Fuzzy Lop

\- Memory debuggers: Valgrind, AddressSanitizer

\- Profilers: DTrace, VTune, Vampir

\- Documentation: Doxygen

\- Debugging (and more): edb, x64dbg

\- Reverse engineering: Radare, Cutter, IDA, Ghidra

And rmsbolt (compiler explorer for emacs)...

------
de_watcher
Forgot rr - reverse debugger: [https://rr-project.org](https://rr-project.org)

Also MXE - cross-compile environment: [https://mxe.cc/](https://mxe.cc/)

------
dclusin
Didn't see any mention of any static analysis tools for C++. Any HN
recommendations?

~~~
jcelerier
\- [https://clang.llvm.org/extra/clang-
tidy/](https://clang.llvm.org/extra/clang-tidy/)

\- cppcheck is sometimes updated also

\- clazy : [https://github.com/KDE/clazy](https://github.com/KDE/clazy)

~~~
Fronzie
Note that [https://clang-analyzer.llvm.org/scan-build.html](https://clang-
analyzer.llvm.org/scan-build.html) is another llvm-based static analyzer.

It does a more deep analysis into the control flow, whereas clang-tidy does
(mostly?) comparatively simpler checks on the AST.

~~~
pnako
You can actually run the static analysis checks from clang-tidy.

~~~
account42
But you won't get the detailed HTML output that tells you why Clang Analyzer
things a problem exists.

------
Const-me
> Visual C++ is a commercial Visual Studio IDE from Microsoft

The OP failed to mention there's a freeware edition.

> It provides the Microsoft Foundation Class (MFC) library which gives access
> to the Win32 APIs.

Last time I used MFC was around 2003. Last time I used Win32 APIs was today.
MFC doesn't give access to anything besides MFC.

~~~
mrpippy
The free (Community) edition is licensed for working on open source projects,
individual developers, and up to 5 users in “non-enterprises” (< 250 PCs or <
$1 Million US Dollars in annual revenue.)

So covers most people, but could be a pain if you’re in a big company that
otherwise doesn’t do much engineering.

~~~
taspeotis
If your company makes a million bucks in revenue it can afford a few Visual
Studio subscriptions. $45/month.

~~~
Longhanks
The harder task is to convince management when there are lots of free
alternatives that "do the same thing".

------
jchw
Clangd is a must have, using clangd in vscode + the Bear tool, you can get
accurate code intelligence for just about any C/C++ project.

------
ferdek
I see no mention of various implementations of C/C++ standard libraries. It's
like the second most important decision to make just after compiler vendor (or
THE most important, whatever your priorities are)

~~~
gpderetta
I would say that in 99% of the cases, using the standard library of the
compiler is the right decision. Also you should target multiple compilers,
possibly on multiple platforms.

------
godelski
Does anyone know a good debugger plugin for vim? I've tried a few and found
them not great. This is seriously the only thing I currently want more from
vim. I keep an IDE around just for this purpose. (A debugger with support for
C++ and python. Don't care if two plugins)

~~~
alexhutcheson
Not within Vim, but I'd recommend running "gdb --tui" in your terminal (not
inside Vim), and then flipping it into "vi mode":
[https://sourceware.org/gdb/onlinedocs/gdb/Readline-vi-
Mode.h...](https://sourceware.org/gdb/onlinedocs/gdb/Readline-vi-
Mode.html#Readline-vi-Mode)

~~~
godelski
I use tui (well I just hit `<C-x>a`) but there's more I want, like color
(because we aren't living in 1970!). Maybe this vi more does the other part I
want, which is code exploration and allow me to select lines for break points
instead of typing as much. But I'm not sure what `M-C-j` is (I'm sure this is
a dumb question). Both of these things are pretty standard in modern gui
debuggers. The other thing I kinda want but isn't necessary is my display
variables to be in a different pane and to have a nerdtree like file
structure.

Frankly a lot of times I know where I need to investigate my in my code. But
it is annoying to switch to vim, find the file and line number, go back to gdb
then do `b my/file/structure/is/long:1825`. That gets hectic in large
projects.

edit: My current setup I used vim+zsh+tmux. So I don't mind having gdb in a
new pane that isn't a vim pane, but I just want colors and some of the basic
features. I don't need everything that the IDEs do, just the basics.

~~~
alexhutcheson
> But I'm not sure what `M-C-j` is

Meta-Control-j

Basically hold down the 'Alt' and 'Control' keys and then press 'j'.

If you don't want to have to toggle it every time you launch gdb, then you can
create a ~/.inputrc file with the following contents:

    
    
        $if gdb
          set editing-mode vi
        $endif
    

If you want vi bindings in every program that uses GNU Readline (Bash, etc.),
then you can leave off the $if/$endif part.

For colors - GDB 8.3 added source code syntax highlighting, but it was just
released this year and may not be the version on your Linux distribution.

------
tpush
These days, I found the best IDE like experience coding C to be CMake
generating the compile_commands.json and a handcrafted .clang-format. Both
used as input to clangd via VSCode’s vscode-clangd plug-in.

Works pretty great!

------
CptMauli
Any good recommendations for logging? (Embedded environment with SD card)

~~~
pnako
spdlog is well regarded (I use it and I like it). It's configurable enough
that should be able to use it in an embedded environment; you can control the
flush policy and use it in either sync or async mode. You can use method calls
or macros (if you want to completely removed things like DEBUG and TRACE calls
in production). You can use it as either header-only or traditional library.

Really it's a great library.

------
idnefju
Had so much trouble trying to get a C++ project cmake setup with opencv 4 in
macOS. Until I found conan.

I have been use to package managers from other languages.

~~~
self_awareness
I've tried to use Conan, but was unable to use 'openssl', because it was named
'OpenSSL'. So, then I wanted to use HarfBuzz library, but Conan was unable to
find one. Later I've found out HarfBuzz exists, but it's named 'harfbuzz'.

The 'case sensitivity' bug was created in 2017, is still open. I think it's
connected to a case sensitivity flag in filesystem which is used in the
system. So, since 99% of Linux systems use case-sensitive fs, it's not usable
on Linux.

~~~
clappski
... I use Conan in projects with dependencies on OpenSSL on Linux and I don’t
have any issues. I use the Makefile generator (because our build system is
plain make + Conan). The name of the package shouldn’t impact you at all,
unless I’m misunderstanding what you mean?

Another example is a dependency on a package called ‘jsonformoderncpp’, which
I use by ‘#include “nlohmann/blah.h”’ - the package name is arbitrary, even if
you have to refer to the dependence using the package name in your build
system rather than the canonical name I don’t see how that would be an issue
(even with FindPackage or whatever you use in CMake)?

------
typon
CoC + ccls + nvim is the fastest, smoothest C++ dev experience I have had yet.
(I use CLion exclusively for debugging)

------
m0zg
No mention of the only build system worth using: Bazel. Fail. No
valgrind/callgrid/cachegrind either. No google-perftools. No Linux `perf`. No
mention of YouCompleteMe. This is not a comprehensive list, to say the least.
I use all of these tools pretty much all the time working with C++.

------
jackewiehose
On emacs use: M-x gud-gdb

~~~
alexhutcheson
"M-x gdb" gives you a more IDE-like experience with more features:
[https://www.gnu.org/software/emacs/manual/html_node/emacs/GD...](https://www.gnu.org/software/emacs/manual/html_node/emacs/GDB-
Graphical-Interface.html)

------
kd3
Microsoft Visual Studio has the best c++ debugger. You get spoiled by it.
Highly recommend it. If you are a beginner start with Visual Studio; it will
make lots of things easier for you. Once Microsoft ports it to Linux the
competition is fucked.

~~~
dralley
Microsoft still hasn't ported Visual Studio to 64 bit, so I don't expect Linux
support is coming any time soon.

~~~
hermitdev
MS has explicitly stated they dont intend or expect to make VS 64-bit in any
near timeframe. They say they dont need to because the components that would
benefit from 64 bit are already out of process and communicate to the main UI
over IPC.

That said, nothing stops a 32 bit VS building/debugging a 64 bit process. I
was doing this 10+ years ago.

MS doesn't support running VS at all on Linux/Mac, and probably won't ever, or
for a very long time out. Use VS Code, instead. Yes, you can target Linux/Mac
from Windows running VS, but VS wont run on the same OS.

~~~
Longhanks
This is a bad excuse for too much (internal) complexity. 64bit is over 10
years old at this point and there's no reason NOT to update programs.

------
ausjke
i bought clion then realized it is really only for cmake-based c++ projects,
yes you can bend others to kind of work but it sucks, i hope clion can work
with autoconf/makefile/cmake/whatever and stay neutral to build tools soon.

still looking for some online c++11 course these days, udemy had none that
looking good.

