When I include boost library hpp header in two translation units, does the boost code compile twice (and the binary size is double, comparing to the traditional precompiled library?)?
How does (boost like) header only libraries influence compilation size?
1k Views Asked by user2449761 At
2
There are 2 best solutions below
0
ChrisWard1000
On
There are some boost header files which are particularly large(I'm looking at you boost/lexical_cast.hpp), which will cause the binary to be larger. However, compilers offer some options to help:
MSVC has an option /LTCG (Link-time Code Generation)
GCC has -flto(I believe is enabled with -O3)
These options generally permit the linker to discard unused components and reduce duplication across the compilation unit.
Related Questions in C++
- How to immediately apply DISPLAYCONFIG_SCALING display scaling mode with SetDisplayConfig and DISPLAYCONFIG_PATH_TARGET_INFO
- Why can't I use templates members in its specialization?
- How to fix "Access violation executing location" when using GLFW and GLAD
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- How do I apply the interface concept with the base-class in design?
- File refuses to compile std::erase() even if using -std=g++23
- How can I do a successful map when the number of elements to be mapped is not consistent in Thrust C++
- Can std::bit_cast be applied to an empty object?
- Unexpected inter-thread happens-before relationships from relaxed memory ordering
- How i can move element of dynamic vector in argument of function push_back for dynamic vector
- Brick Breaker Ball Bounce
- Thread-safe lock-free min where both operands can change c++
- Watchdog Timer Reset on ESP32 using Webservers
- How to solve compiler error: no matching function for call to 'dmhFS::dmhFS()' in my case?
- Conda CMAKE CXX Compiler error while compiling Pytorch
Related Questions in BOOST
- build boost use libc++ on linux use wrong --target
- fatal error: 'boost/version.hpp' file not found
- Having problems using boost spirit to identify token string with double brackets
- Calculate percentile (P50, P95) using Boost
- C++ Boost program how to statically compiled with musl libc?
- Boost system segmentation fault when not inlining
- converting utf8 to utf32
- Cmake error : Configuring incomplete, errors occurred
- Including boost-1.83.0 is causing compilation errors on windows
- How to randomly sample from a skewed gaussian distribution in boost c++?
- Conda cxx-compiler, cannot find boost header despite cmake finds boost
- how to get notified about signal connects and disconnects from slots with boost signals2
- how to validate ssl certificate with boost and openssl
- Can't start server in C++ using boost/asio
- Creating std subrange from boost archive iterators
Related Questions in COMPILATION
- I am trying to run java application in Eclipse, When I try to do Run > Run as > Java Application it starts to show little processing but nothing happe
- Unable to run get .exe file from assembly NASM
- Javascript to Java
- How to compile only the changed files in Verilator?
- Why does the .exe file become locked after compiling?
- Installing the C compiler for LC3
- compile syzkaller fuzzer failed without any error or warning
- Solved: Create standalone executable for MacOS with OpenCV and libmagic
- How to work around the "collect2: error: ld returned 1 exit status" error when running simple fortran files with the gfortran command?
- how to add a compiler type supported for sccache?
- Vulkan ‘VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR’ was not declared in this scope
- Rust newbie compile error (for (key: String, value: String) in | ^ expected one of `)`, `,`, `@`, or `|`)
- latest version of redshift with crazy compile times
- Problem compiling out-dated Typescript code
- What is appropriate substitution for configurations.compile in newer gradle e.g. version 8.7?
Related Questions in HEADER-FILES
- C++ - Unknown type name
- Unable to install old gcc version on Mac using homebrew. Error in make possibly due to incorrect header file version
- External macro definition in header
- How to create your own C++ Library and share it with others so that everyone can use it?
- White space to the right side of my header/navbar
- How C ++ header files hold the cpp respective file definitions if they do not include them on themselves?
- Trying to render texture but I can't pass the variable to draw function
- Question about header files and functions in separate files in C++
- Visual Studio Additional Include Directories
- Initializing a large map in header cause g++ crashes
- Umbrella-Header uses wrong import syntax after `pod install`
- The game module "project name "could not be loaded. There may be an operating system error or module may not be properly setup
- Why does it throws an error while putting functions into header in VSCode but not GCC?
- Why net/if.h before ifaddrs.h?
- Error about the Redefinition of a struct and conflicting types for a function
Related Questions in PRECOMPILE
- How do publish a webforms website without including the aspx.cs files
- Stored procedure or view
- Is it possible to check for a given python file whether it's pyc file is valid and up to date?
- aspnet_compiler.exe not finding dependentAssembly
- How to fix `failed to load command: bootsnap (/rails/vendor/bundle/ruby/2.7.0/bin/bootsnap)` while deploying through fly.io
- VS2022 nis not compiling typescript files to js files
- VS2022 IISExpress test yield errors in phantom ts files
- C++ "error C1010: unexpected end of file while looking for precompiled header" when adding new .h and corresponding .cpp just for new files
- ActionView::Template::Error: Invalid CSS syntax with "select-bg-img" selector and "background-image" property in Rails application
- How can I force a Julia package to redo precompilation?
- Rails - Ruby 3.1.1 will not load on CentOS but okay on OSX
- How can I fix a Rails 5 precompile assets rb_sysopen error?
- PRo*C curses.h not identifying _Bool unable to precompile
- How to use code from optional subspec in core subspec
- Julia doesn't precompile Plots
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You've asked two distinct questions:
does the boost code compile twice? Yes it does. The net effect is that compilation time is probably a little longer as the compiler has to digest all the headers for each compilation unit.
the binary size is double? No it probably does not, but that will come down to your choice of optimisation flags. A template instantiated in unit A will notionally share the same implementation code as one instantiated in unit B with exact same type parameters.
Whether it actually shares the same code will depend on whether your optimisation flags permit inlining of the template implementation. If you have allowed inlining and the compiler has chosen to do it then your binary size will increase as the compiler places the template implementation inline with your code in order to achieve your stated optimisation goals.
Inlining is never possible with a binary-only library and so this is one reason why your binary size could grow when using header-only libraries.
Here's an example to show how gcc shares template implementation when inlining is not enabled:
a.cpp
b.cpp
m.cpp
compilation
analysis of objdump
Note how the same implementation of
push_backis used (location 400976) even though it was compiled into completely separate compilation units.