Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very long linking time with -g and without -DNDEBUG options

I'm building a third-party CMake-based C++ project.

Building the project in release mode only takes a couple of seconds. The linking stage takes less than a second (when make prints Linking CXX executable myproject.exe).

Building in debug mode takes more than a minute. Most of this time is spent linking the executable. This happens even during subsequent builds after minimal changes to the code.

The difference to the release mode seems to be the -g option vs. the -O3 -DNDEBUG options. Is this behavior expected? I've worked on similar sized projects before (~18k LOC), but I've never experienced such a big difference in compile time between debug and release modes.

This takes 50 seconds:

C:\msys64\mingw64\bin\g++.exe  -std=c++0x -Wall -Wextra -Wpointer-arith \
-Wcast-align -fstrict-aliasing -Wno-unused-local-typedefs -fvisibility- \
inlines-hidden -march=native -g   -Wl,--whole-archive \
CMakeFiles\myproject.dir/objects.a -Wl,--no-whole-archive \
-o myproject.exe -Wl,--major-image-version,0,--minor-image-version,0 \
@CMakeFiles\myproject.dir\linklibs.rsp
like image 474
Jawap Avatar asked Nov 08 '17 13:11

Jawap


1 Answers

Unfortunately, link times for large projects can be quite slow, especially in debug mode. Things that usually help are

  • splitting a project to shared libraries (that's done, e.g., by LLVM developers)
  • linking on SSD (or tmpfs)
  • using the Gold linker instead of the default BFD linker (or maybe even LLD as it's getting more stable)
like image 188
yugr Avatar answered Nov 09 '22 23:11

yugr