I want to compile a C++ program so that it dynamically links to libc, but does not have a dynamic dependency on libstdc++. for example 'hello world' using std::cout, when compiled with the -static-libstdc++ -flto flags, the output executable file is 1 MB in size (Arch linux amd64). I want an effect similar to using build-std in rust, so that the 'hello world' program takes up space the same whether using std::cout or using printf.
g++ - analogue to rust's build-std
59 Views Asked by kvas97 At
1
There are 1 best solutions below
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 G++
- File refuses to compile std::erase() even if using -std=g++23
- Can't resolve undefined reference to box2D C++
- Is this a GCC optimiser bug or a feature?
- Problem with compiling c++ project that is running python code using Python.h -> undefined reference
- weird > thing when compiling for sdl2 in g++
- cmake and g++ cross compilation looking for library in host sysroot path instead of target sysroot
- g++ / vscode apparently cannot see my src folder? "cc1plus.exe: fatal error: src/glad.c No such file or directory"
- compile masstree from source in riscv64
- C++: undefined reference to `xxx`
- Problem with g++ on Mac using std::thread and exceptions
- Why is the size of the bit-field structure different from what I think?
- g++ ok but clang no: return rvalue to lvalue
- Trouble setting up c++ with VSCode. Include error, missing binary operator and xlocale.h not found
- Trying to understand the fields of std::_Sp_counted_base in gcc's bits/shared_ptr_base.h header file
- g++: fatal error: cannot execute ‘d21’: execvp: No such file or directory compilation terminated
Related Questions in CLANG++
- File refuses to compile std::erase() even if using -std=g++23
- Get search paths for headers in the standard library in Clang?
- Is this a GCC optimiser bug or a feature?
- How can I switch from clang11 to clang14 on freebsd?
- Why breakpoint location is +4 bytes to the function address?
- How to fix loop not unrolled: the optimizer was unable to perform the requested transformation in clang?
- Problem with g++ on Mac using std::thread and exceptions
- g++ ok but clang no: return rvalue to lvalue
- how to fuzz program using libfuzzer?
- Why is bitset::set() triggering undefined behavior
- Android NDK: Linker Script .ld: OVERLAY : gives ld:4: malformed number: :
- How to generate binary executable from linked LLVM IR of CUDA files?
- How to use clang -cc1 to link object files
- clang 18 gives error "non C++20 importable modules" for "import std"
- Why is jthread not presented in libc++ (using clang 18, c++26)
Related Questions in STATIC-LINKING
- Linking GLFW with a static library using Premake
- Conan: How to get the exact version of a statically linked library contained in a pre-built package?
- undefined reference to `__mingw_vsscanf' while trying to link GLFW statically on VScode
- How do I override location for dynamically linked libgcc_s?
- CMake: Selectively relinking function calls
- Is mixing dynamic and shared libraries a good idea when creating an ODBC Driver?
- Linker cannot find strnstr() on Ubuntu with libbsd
- Compiling libR (from the R statistical package) as a standalone C library for java+jni
- FTGL linking to Visual studio 2022 (x86) using VCPKG C++
- g++ - analogue to rust's build-std
- Statically compile gcrypt
- What exactly is static variable behaviour in multiple linkeage of a library that contains it in C++?
- LNK2019 error when trying to use Stanford external C++ libraries in Visual Studio
- Build Python as static library with won't include basic modules
- What is the linux command that gives the paths to libraries for linking during c++ compilation?
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?
C++'s iostream library, including
std::cout, is a huge library.If you are using it, you either need to link to a dynamic library that contains the huge library, or you need to statically link it and include the huge library in your executable.
It isn't plausible for the C++ compiler to eliminate it and translate everything down to C calls sadly.
There is a chance that if you recompiled the entire C++ chain of libraries and used link time optimization your compiler could aggressively work out a way to reduce it to C calls, but even that is unlikely - the relative complexity of iostreams is high, with lots of internal virtual classes, all of which would require a fair amount of luck to optimize out completely.
Now, this isn't true of other parts of the C++ standard library; many of them could plausibly optimize away, like the standard container and most of the algorithms library. It is just that iostreams is, frankly, bloated and not that well designed, especially with your goals in mind. It was an early C++ library and it was decades ago.