Towards a cross-platform C/C++ dev environment

As you’ve probably read in my recent posts, I’ve been getting involved in the linux audio community. I’ve discovered that I really like linux – especially the concept of a system-wide package manager, I wish Windows had one that everybody used.

What I miss is Visual Studio. I really can’t overstate the hit my velocity has taken without intellisense. Its not that I’m incapable of programming without it, but it takes such a long time to look through html SDK/API docs. So, I’ve been trying to sort out a system where I can lint my code, build my projects, get some form of auto-complete, and have a few other C/C++ specific conveniences, like switching between .h* and .c* files with the same base name. I also don’t want to be tied to a build system. I’m kinda greedy, I want a graphical debugger if I can. I’ve got a solution now which shows potential.

As text editors go, I’ve grown to like Atom by GitHub over the last year or so. It is built in JavaScript (mostly, they moved a few things down to native code for performance, it is now quite slick, and a lot better than it was even 6 months ago), and it is super extensible, but in a nice way, not like Eclipse.

Triggering builds

One of the challenges with Linux is that there are quite a few build systems in common use: autotools, scons, waf, cmake to name a few. I like waf, but autotools is super common. Anyway, I didn’t want to be tied to a build system, but I do want to do basic things like build or configure my project from a keyboard shortcut. There’s a nice plugin for this: build. It has a bunch of built-in build systems that are mainly web-focused, but it lets you basically tie any shell command to the keyboard shortcut if you want, by providing a file called .atom-build.json.

Here’s what mine looks like:

     "cmd": "./waf",
     "name": "Build",
     "sh": "true",
     "targets" : [
               "cmd": "./waf configure",
               "name": "Configure",
               "sh": "true"

It’s not perfect – if you switch target it remembers which is a pain for doing things like configure, or clean, which you do once in a while, then go back to building. I’ll probably fork it and make a more C/C++ centric version one day, but it works well enough. Install it as follows:

> apm install build

Ok, so I can build, and each time I build, I get to see what’s wrong but sometimes deciphering a big blob of compiler output is difficult, and slow. Atom has a plugin which gives a generic linting infrastructure. I guess it was originally built for JSLint or something. Users can create providers to this linter to handle various languages, and it just so happens there is one which uses GCC, and one which uses Clang, so take your pick. I’m using the GCC one.

> apm install linter linter-gcc

You can change the default compiler flags, so I added -Werror, to make warnings appear as errors – I use that in my build script as well. linter-gcc supports a per-project config file which allows you to configure the settings per project, called .gcc-flags.json. I haven’t had to add any flags to it as yet, but at some point I’ll write a waf plugin to dump my CFLAGS and CXXFLAGS into this file whenever I configure. If you use autotools, I’m sure your configure script could do something like that too. A note about this one: at the time of writing (version 0.36.0), this plugin is actually a little broken. I fixed it and the PR was merged, so you should probably get it from source instead, or install it with apm and then replace the main.js with one from github.


Again, Atom has existing auto-complete infrastructure in the form of the autocomplete-plus plugin, which can be extended by providers – in this case autocomplete-clang. Now this is one of the key reasons LLVM and Clang were created, to be used in tool integrations. You’ll need to have Clang installed such that the clang executable is on your path, but that’s easy on all platforms. Install the plugins with:

> apm install autocomplete-plus autocomplete-clang

You can customize your cflags etc per project with a .clang_complete file, which is the same file used by the clang-complete plugin for VIM, which is neat. Again, I haven’t had to modify these yet, but getting waf to auto-generate the file should be pretty easy.

Switching files

Ok, so we can build, lint, and auto-complete now. All that’s left from my wish-list is switching between header and source files with the same name, and debugging. Lets deal with the former, there’s a plugin for that.

> apm install switch-header-source

This one is probably the least satisfying. I’ve installed a plugin called atom-debugger, which basically bootstraps gdb. At the moment it is very basic, but I think it could be improved quite quickly, so I’ll probably find myself contributing to it. Install it with:

> apm install atom-debugger

Linux is actually a really awesome environment to write code in, mainly because of system wide package management, and a defined scheme for where libraries, headers etc go, which means that you very seldom have to add special include or lib directory paths to your compiler flags. Visual Studio is an incredibly powerful IDE, which you miss when you are relegated to a mere text editor. Atom, is a great, highly extensible text editor which can be extended to give you quite a functional IDE for developing in C/C++, without being tied to a buildsystem or compiler, and it can be done on Linux, OSX and Windows. Boom.


13 thoughts on “Towards a cross-platform C/C++ dev environment

    1. I have indeed tried Qt Creator, and it is a fantastic tool, but it is tied to its own project format and build system. Don’t get me wrong, if I’m using Qt, I use Qt Creator. I like MSYS2 and pacman as well. What would be really good is if it integrated with the Windows 10 “MyGet” effort.

  1. Qt Creator is absolutely not tied to Qt, the name unfortunately makes it seem that way. It supports the CMake and Autotools build systems as well as the Qt-invented ones (qmake and QBS, both of which *can* be used outside of Qt) and many compilers and cross-compilers. It can also be used for Android and iOS development, again without needing to build Qt-based projects (in all honesty I’ve not tried that for iOS so I could be wrong). I use it extensively for bug-fixing the packages of MSYS2, yeah, I admit I am something of a fan of it 🙂

    I don’t really understand NuGet / OneGet / MyGet. I skim read Scott Hanselman’s blog posting about OneGet describing it (or was it Chocolatey?) as apt-get for Windows. As best I understand it, OneGet seems like a meta package manager which leads inevitably to a mix of lowest common denominator of feature sets or very patchy implementation of features on some ‘backends’, and MyGet seems to be a product from some company in Belgium trying to make money on top of NuGet, so I assume you mean OneGet instead?

    MSYS2 with Pacman is all about Open Source packages, built from source using makepkg and makepkg-mingw. The users’ freedom to do the same is respected and encouraged.

    Anyway, given the title of this post, none of those technologies are interesting from a cross platform perspective since they’re tied to MS Windows.

    1. I couldn’t move your comment to the other thread, but that’s ok. I didn’t realise QT Creator could use other build systems, I did know it supported other compilers though.

      I think OneGet is what I meant. You’re right, it is a meta-package manager, but at this stage I’m in support of any attempt by MSFT to move in that direction. I quite like MSYS2 – I made a post about building Ardour with it last week. I might email you a few questions that I had about it actually.

  2. I tried to get atom c/c++ autocompletion to work. I’ve installed autocomplete-plus, autocomplete-clang and clang itself and created a .clang_complete file, but atom doesn’t complete anything. How can I find out what’s wrong? Is there a logfile or something?

    1. Hi Gernot,

      I haven’t tried with autocomplete-clang yet, I’ve mainly been using autocomplete-gcc. The packages are all javascript though, so you can probably add some logging somewhere if you are motivated.


  3. Let me add that a new package (since Aug 2016) is around: “atom-clang” []. It uses clang library directly, providing much faster auto-completion.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.