3

In C, I could use the tcc, but I wasn't able to find anything for c++.

A single .cpp file changed in Eclipse with the Gcc takes ~5 seconds to recompile, that's ridiculous. I don't care about how the code performs, I just need a faster testing cycle.

Any ideas to make the code compile faster?

m.s.
  • 16,063
  • 7
  • 53
  • 88
Blub
  • 13,014
  • 18
  • 75
  • 102
  • 6
    How much of that overhead is due to Eclipse? I’ve never used it for C++ myself but judging from a colleague, Eclipse adds quite some overhead to C++ compilation. Furthermore, how much time does compilation take, how much does the linking? Can you perhaps reduce header usage and split code into more separate compilation units? – Konrad Rudolph Jun 13 '11 at 19:06
  • 4
    Read http://stackoverflow.com/questions/58841/precompiled-headers-with-gcc about precompiled headers. That might be helpful – Grzegorz Szpetkowski Jun 13 '11 at 19:06
  • The compiling speed of a file depends on the code that's inside it. How complex/big is your .cpp file? – karlphillip Jun 13 '11 at 19:08
  • 14
    To see the compiler performance, run it from the command line. Eclipse is super slow (Java...) – Alex F Jun 13 '11 at 19:10
  • @karlphilip It's very short, just 50 lines of code. – Blub Jun 13 '11 at 19:16
  • 2
    Compiling with command-line will be faster and also you can enable compiler cache with setting this environment variable: `USE_CCACHE=1` it will make your compilation up to `40%` faster. – fardjad Jun 13 '11 at 19:20
  • 2
    Clang is notably faster than gcc, give it a try. – SK-logic Jun 13 '11 at 19:28

5 Answers5

6

For a 50-line file on my not very fast laptop, compile times are of the order of 1.5 seconds with g++ from the command line - obviously this depends on a lot of other factors, like what headers are included. For the Code::Blocks IDE, which is written in C++, compilation of the same files (or to be more accurate, reporting the results of compilation) is perhaps double this. I'm not surprised that an IDE written in Java is even slower.

3

Check out clang

Nemanja Trifunovic
  • 24,346
  • 3
  • 50
  • 88
  • 3
    @Blub: Since you accepted this answer, can you comment on how much improvement you're seeing from (presumably) using clang from Eclipse instead of gcc ? Thanks! – timday Jun 13 '11 at 20:29
  • 1
    @timday: I accepted it because it most closely fit the question. What I ended up doing, is using QtCreator. It's the same compiler, but my compile time has been cut down to about 2 seconds instead of 5 with Eclipse. Good enough for me right now. Setting up Clang with Eclipse is still experimental at this point, and I didn't want to use alpha software. – Blub Jun 15 '11 at 11:26
1

In 2018 there is clang-based compiler called zapcc. It is at least 2x faster on first build and more than 20x faster on rebuild due to caching.

However, it require much more memory than gcc or clang.

val - disappointed in SE
  • 1,475
  • 3
  • 16
  • 40
1

Eclipse is taking so much RAM, it's not unlikely that your operating system starts swapping when it has to run a compiler too.

GDR
  • 2,301
  • 1
  • 21
  • 26
0

May be a workaround might be to divide the C++ project to sub-components and compile the whole project with some high optimization level. Then, during development, recompile only the parts that changed with no optimization at all by using GCC/LLVM flag -O0 (letter "o" and digit "zero").

The key part to such a solution is a fine build system. As of 2015 I use Rake, which is a Ruby analogue to the GNU Make. Rakefile is an ordinary Ruby file that just loads a Rake specific library. The Rake tasks are essentially global Ruby functions, which means that anything that can be written in Ruby, can be executed from a Rake task. As of 2015 I use Rake tasks for starting self-tests, starting tests of a specific component (during the "test driven development"), building, code generation, etc.

  • As of 2015 the corporate Java world seems to like Gradle, which is a successor of the Apache Maven, which is a successor of the Apache Ant.
  • Open source scientific C++ software projects seem to find CMake practical. The Boost C++ library seems to offer Boost.Build.

On multi-core CPU's the classical GNU Make can build multiple files in parallel, if it receives the -j command line option.

charmoniumQ
  • 5,214
  • 5
  • 33
  • 51
Martin Vahi
  • 129
  • 1
  • 5