r/cpp • • Aug 10 '26

GCC Build Experience

0 Upvotes

Firstly, you need a native installation of g++ and binutils via your package manager, then you need sysroots for your target platforms(probably x64 glibc linux and arm64 glibc linux).

The workflow goes like this, to cross compile GCC itself to run on another arch, in my example from arm64 binary targeting x64 you follow this build order. I'm assuming an x64 system

x64 binutils -> x64 gcc -> arm bintutils(--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=aarch64-linux-gnu) -> gcc (x64->arm64) -> binutils(arm64->arm64) -> gcc(arm64->arm64) -> bintutils(arm64->x64) -> gcc(arm64->x64)

Now a couple of rules, pass --with-build-sysroot when building a normal compiler such as x64 -> x64 and pass --with-sysroot when building a cross, your toolchain flags won't matter at all in the eyes of GCC autoconf script.

You need to embed flags into env vars like CC to make sure stuff passes sometimes, it is actually quite verbose, you do the same thing at CC, CC_FOR_BUILD, CFLAGS AND CFLAGS_FOR_BUILD.

I recommend disabling multilib,gdb,werror and lto and always disabling bootsrap, you can do those but I don't recommend it.

You have to pass -Wl,--undefined-version if you use lld rather than ld. Otherwise your build will fail.

Here is an example toolchain I used to compile a arm64 -> x64 compiler in my x64 host

BUILD_SYSROOT=/home/mccakit/dev/sdk/debian-12-x64
HOST_SYSROOT=/home/mccakit/dev/sdk/debian-12-arm64
TARGET_SYSROOT=/home/mccakit/dev/sdk/debian-12-x64
BUILD_GCC_BIN=/home/mccakit/dev/compilers/gcc/linux-glibc-x64/bin
HOST_GCC_BIN=/home/mccakit/dev/compilers/gcc/linux-glibc-arm64/bin
TARGET_GCC_BIN=/home/mccakit/dev/compilers/gcc/linux-glibc-x64/bin
BUILD_BINUTILS_BIN=/home/mccakit/dev/compilers/binutils/linux-glibc-x64/bin
HOST_BINUTILS_BIN=/home/mccakit/dev/compilers/binutils/linux-glibc-arm64/bin
TARGET_BINUTILS_BIN=/home/mccakit/dev/compilers/binutils/linux-glibc-x64/bin
LLVM_BIN=/home/mccakit/dev/compilers/llvm/bin
CCACHE=/home/mccakit/dev/tooling/ccache/bin/ccache
export CC="${CCACHE} ${HOST_GCC_BIN}/aarch64-linux-gnu-gcc -B${HOST_BINUTILS_BIN} -B${LLVM_BIN} --sysroot=${HOST_SYSROOT} -Os -DNDEBUG -w -ffunction-sections -fdata-sections -fuse-ld=lld -Wl,--gc-sections -Wl,--undefined-version"
export CXX="${CCACHE} ${HOST_GCC_BIN}/aarch64-linux-gnu-g++ -B${HOST_BINUTILS_BIN} -B${LLVM_BIN} --sysroot=${HOST_SYSROOT} -Os -DNDEBUG -w -ffunction-sections -fdata-sections -fuse-ld=lld -Wl,--gc-sections -Wl,--undefined-version"
export AR="${HOST_BINUTILS_BIN}/aarch64-linux-gnu-ar"
export NM="${HOST_BINUTILS_BIN}/aarch64-linux-gnu-nm"
export RANLIB="${HOST_BINUTILS_BIN}/aarch64-linux-gnu-ranlib"
export AS="${HOST_BINUTILS_BIN}/aarch64-linux-gnu-as"
export STRIP="${HOST_BINUTILS_BIN}/aarch64-linux-gnu-strip"
export CFLAGS="-Os -DNDEBUG -w -ffunction-sections -fdata-sections"
export CXXFLAGS="-Os -DNDEBUG -w -ffunction-sections -fdata-sections"
export LDFLAGS="-fuse-ld=lld -Wl,--gc-sections -Wl,--undefined-version"
export CC_FOR_BUILD="${CCACHE} ${BUILD_GCC_BIN}/gcc -B${BUILD_BINUTILS_BIN} -B${LLVM_BIN} --sysroot=${BUILD_SYSROOT} -Os -DNDEBUG -w -ffunction-sections -fdata-sections -fuse-ld=lld -Wl,--gc-sections -Wl,--undefined-version"
export CXX_FOR_BUILD="${CCACHE} ${BUILD_GCC_BIN}/g++ -B${BUILD_BINUTILS_BIN} -B${LLVM_BIN} --sysroot=${BUILD_SYSROOT} -Os -DNDEBUG -w -ffunction-sections -fdata-sections -fuse-ld=lld -Wl,--gc-sections -Wl,--undefined-version"
export AS_FOR_BUILD="${BUILD_BINUTILS_BIN}/as"
export AR_FOR_BUILD="${BUILD_BINUTILS_BIN}/ar"
export RANLIB_FOR_BUILD="${BUILD_BINUTILS_BIN}/ranlib"
export NM_FOR_BUILD="${BUILD_BINUTILS_BIN}/nm"
export CFLAGS_FOR_BUILD="-Os -DNDEBUG -w -ffunction-sections -fdata-sections"
export CXXFLAGS_FOR_BUILD="-Os -DNDEBUG -w -ffunction-sections -fdata-sections"
export LDFLAGS_FOR_BUILD="-fuse-ld=lld -Wl,--gc-sections -Wl,--undefined-version"
export CC_FOR_TARGET="${CCACHE} ${TARGET_GCC_BIN}/gcc -B${TARGET_BINUTILS_BIN} -B${LLVM_BIN} --sysroot=${TARGET_SYSROOT} -Os -DNDEBUG -fPIC -w -ffunction-sections -fdata-sections -fuse-ld=lld -Wl,--gc-sections -Wl,--undefined-version"
export CXX_FOR_TARGET="${CCACHE} ${TARGET_GCC_BIN}/g++ -B${TARGET_BINUTILS_BIN} -B${LLVM_BIN} --sysroot=${TARGET_SYSROOT} -Os -DNDEBUG -fPIC -w -ffunction-sections -fdata-sections -fuse-ld=lld -Wl,--gc-sections -Wl,--undefined-version"
export AR_FOR_TARGET="${TARGET_BINUTILS_BIN}/ar"
export NM_FOR_TARGET="${TARGET_BINUTILS_BIN}/nm"
export RANLIB_FOR_TARGET="${TARGET_BINUTILS_BIN}/ranlib"
export AS_FOR_TARGET="${TARGET_BINUTILS_BIN}/as"
export CFLAGS_FOR_TARGET="-Os -DNDEBUG -fPIC -w -ffunction-sections -fdata-sections"
export CXXFLAGS_FOR_TARGET="-Os -DNDEBUG -fPIC -w -ffunction-sections -fdata-sections"
export LDFLAGS_FOR_TARGET="-fuse-ld=lld -Wl,--undefined-version"
export PATH="${BUILD_BINUTILS_BIN}:${BUILD_GCC_BIN}:${HOST_BINUTILS_BIN}:${HOST_GCC_BIN}:${PATH}"

Final Result

root@24a3b7f889f7:/tmp# uname -m
aarch64
root@24a3b7f889f7:/tmp# 
root@24a3b7f889f7:/tmp# x86_64-linux-gnu-g++ -B/mccakit/binutils-x64/bin --sysroot=/mccakit/debian-12-x64 hi.cc -o hi_x64
root@24a3b7f889f7:/tmp# ls /mccakit/
binutils-arm64	binutils-x64  debian-12-x64  gcc-arm64	gcc-x64
root@24a3b7f889f7:/tmp# 
mccakit@mccakit-pc:~/desktop$ sudo ./x64_bin 
[sudo] password for mccakit:           
hello world
mccakit@mccakit-pc:~/desktop$ 

Here are the prebuilt GCC binaries for lazy folks https://github.com/mccakit/prebuilt_gcc

Conclusion: Use clang, honestly I don't recommend gcc unless you have to. It is easier to build and run.


r/cpp • • Aug 10 '26

Jessesort is now faster than std::sort on every input type

0 Upvotes

Repo here: https://github.com/lewj85/jessesort

tl;dr Jessesort is up to 20% faster than std::sort on random inputs and up to 95% faster on structured inputs

Jessesort has two phases: insertion and merging. The insertion phase routes inputs to two games of Patience (similar to Solitaire). One game has ascending piles and the other has descending piles. Routes inputs to the optimal game based on current run direction. Make base array copies for pile tails to speed up binary search. Faster merge logic than the old Patience sort k-way.

Jessesort was already faster on structured inputs, but the new optimization changes finally pushed this past the goal of being faster on random inputs too. Added seven variations of the algorithm. The fastest on random input is V2 that simulates both Patience games and uses a blueprint to track ascending vs descending game and pile index in that game. It's up to 20% faster on random inputs and up to 95% faster on structured inputs.

Key changes introduced were: early input probing to route random-like and structured data into better insertion paths, removal of pile hints where direct bit-walk search proved faster, simulated pile layouts that reduce allocation and bookkeeping overhead, adaptive merge routing based on the structure produced during insertion, branchless merging with a tuned four-way unroll, reconstruction optimizations that simplify blueprint decoding and cursor updates, pointer-based merge kernels that substantially reduced hot-loop overhead, selective early freezing/overflow strategies in later variations, preservation of fast monotonic/structured-input exits, and targeted SIMD experiments that use fixed-width AVX2 comparisons where the pile shape makes them worthwhile.


r/cpp • • Aug 08 '26

Bjarne Stroustrup, creator of C++, joins Susquehanna

Thumbnail cppcon.org
114 Upvotes

r/cpp • • Aug 08 '26

GCC should ship prebuilt binary tarballs like LLVM

16 Upvotes

It is really annoying, when you wanna test something you can't just download a previous release like llvm, so it is very hard to check if there is a regression.

Also, the default build of c and c++ only, takes like an hour because of triple consecutive builds. So every time you have to lookup to that weird flag on the internet to turn that off.


r/cpp • • Aug 07 '26

GCC 16.2.0 Released

Thumbnail phoronix.com
168 Upvotes

I'm pretty excited about this maintenance release. I think this will be the first version of gcc which can compile my project.


r/cpp • • Aug 07 '26

Boost.Multi Multi Mini-Review Begins Today (7 Aug - 12 Aug)

20 Upvotes

Hello,

Today begins the mini-review of Multi, authored by Alfredo Correa. Multi is a modern C++ library that provides manipulation and access of data in multidimensional arrays for both CPU and GPU memory. The review will run through Wednesday 12 August.

You can find the library and documentation links below:
- https://github.com/correaa/boost-multi
- https://correaa.github.io/boost-multi/multi/intro.html

The review earlier this year raised a number of issues that primarily revolved around the state of the documentation, not the library itself. I have labeled all of the issues related to conditions found in last review, and many have notes or resolution from Alfredo:

https://github.com/correaa/boost-multi/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22Boost%20review%22

To this end the review will revolve around the current state of the documentation on the branch "boost_review". In your review please explicitly state if you recommend REJECT, ACCEPT, or a conditional acceptance along with the acceptance conditions.

Please let me know if you have any questions or concerns. Thank you in advance for your time.

Matt
Multi Review Manager

Edit: Link to the previous review thread is here: https://www.reddit.com/r/cpp/comments/1rlhm4g/boostmulti_review_begins_today/


r/cpp • • Aug 06 '26

C++ Show and Tell - August 2026

49 Upvotes

Use this thread to share anything you've written in C++. This includes:

  • a tool you've written
  • a game you've been working on
  • your first non-trivial C++ program

The rules of this thread are very straight forward:

  • The project must involve C++ in some way.
  • It must be something you (alone or with others) have done.
  • Please share a link, if applicable.
  • Please post images, if applicable.

If you're working on a C++ library, you can also share new releases or major updates in a dedicated post as before. The line we're drawing is between "written in C++" and "useful for C++ programmers specifically". If you're writing a C++ library or tool for C++ developers, that's something C++ programmers can use and is on-topic for a main submission. It's different if you're just using C++ to implement a generic program that isn't specifically about C++: you're free to share it here, but it wouldn't quite fit as a standalone post.

Last month's thread: https://www.reddit.com/r/cpp/comments/1umnaxs/c_show_and_tell_july_2026/


r/cpp • • Aug 06 '26

Neoclassical C++ (2): Exploring input-output segmented algorithms

Thumbnail boostedcpp.net
24 Upvotes

Hi,

I've written a new blog entry continuing my previous article about segmented iterators. This time trying to analyze how to apply Matt Austern's segmented iterator pattern to input-output algorithms likecopy, copy_if, etc., benchmarking the experimental implementation from Boost.Container vs the standard library.

New article link: https://boostedcpp.net/2026/08/06/neoclassical-c-2-exploring-input-output-segmented-algorithms/

Happy to receive feedback!


r/cpp • • Aug 06 '26

C++26: #embed

Thumbnail sandordargo.com
137 Upvotes

r/cpp • • Aug 05 '26

Boost.Int128 has been accepted

126 Upvotes

Boost.Int128 from Matt Borland has been accepted into Boost. Arnaud Becheler managed the review.


r/cpp • • Aug 05 '26

C++26 Reflection: Simplifying JSON Serialization

Thumbnail techfortalk.co.uk
53 Upvotes

I have been exploring the new additions in C++26, and I have been discussing the reflection feature that has come with C++26. In the last post, I discussed what is reflection and how to use it and how to use it with a simple example, particularly with an enum class. Since then, there have been suggestions to provide an example which is more than a toy :). In this post, I have discussed how to use reflection for JSON serialization, which is something we often have to do. This example is somewhat taken from real-world code but has been stripped down significantly. Suggestions are always welcome.


r/cpp • • Aug 05 '26

C++Now C++Now 2026: A Path to Pratically Safe C++ talk by Google's C++ Safety Team

Thumbnail youtube.com
52 Upvotes

r/cpp • • Aug 06 '26

Faster KNN search in Manticore: 2-pass HNSW, batched distances, and AVX-512

Thumbnail manticoresearch.com
2 Upvotes

Three changes to the HNSW search engine improve KNN throughput by up to 29% at high k, with over 20% gains under concurrent load. No API changes, no index rebuild, no configuration. Just faster searches.


r/cpp • • Aug 05 '26

Faster Than Ninja

Thumbnail build2.org
65 Upvotes

r/cpp • • Aug 03 '26

Common Problems I see with Public Libraries Build Scripts

26 Upvotes

Hi, I'm an early user of Common Package Specification and C++ modules. I package and port libraries for my own use frequently.

I want to talk about issues I see constantly.

- Having specific options for sanitizers, exceptions etc, this is a toolchain problem, if I wanna build your library with sanitizers I can just add the flags to my cmake toolchain file same as allocators.

- Not separating build options to a separate file, meson already does this, it ain't that hard to do in cmake, just cache variables in a separate file at project dir which you include before subdirs

- Making tests separate cmake projects rather than just executables, just why?

- Vendoring dependencies, copy pasting files from other projects rather than just consuming these external libs via packages.

- Using unnecessary helper functions that really makes the cmake script unreadable. Build scripts don't need to be over engineered, they are just basic scripts in which you define very basic information.

I could go on but I'm tired.


r/cpp • • Aug 03 '26

Using Alpaka to GPU-Accelerate CAPOW: A Case Study, Wed, Aug 12, 2026, 6:00 PM

Thumbnail meetup.com
5 Upvotes

CAPOW is a continuous-valued cellular automata explorer with update loops that look GPU-friendly: one work item per cell, small-neighborhood stencils, ping-pong buffers, and pointwise nonlinear rules.

This month, Richard Thomson will present a case study in using Alpaka (An Abstraction Library for Parallel Kernel Acceleration) to move a CAPOW-like update rule onto CUDA without porting CAPOW itself. We'll walk through the spike: CMake/vcpkg setup, CUDA language support, the CPU reference path, the Alpaka CUDA kernel, correctness checks, timing results, and the parts that hurt.

The first pass showed zero CPU/GPU error and strong update-only speedups, including about 102x at 1000 x 1000 and 174x at 1920 x 1080 for the diffusion rule.

We'll also discuss whether Alpaka is earning its keep compared with writing direct CUDA.

This will be an online meeting, so drinks and snacks are on you!

Join the meeting here: https://meet.xmission.com/Utah-Cpp-Programmers


r/cpp • • Aug 02 '26

How fast is C++26's std::hive?

Thumbnail lemire.me
255 Upvotes

r/cpp • • Aug 03 '26

New C++ Conference Videos Released This Month - August 2026

10 Upvotes

C++Now

2026-07-27 - 2026-08-02

C++Online

2026-07-27 - 2026-08-02

ADC

2026-07-27 - 2026-08-02


r/cpp • • Aug 03 '26

Performance with custom data flexibility and no inheritance

7 Upvotes

I am in an argument. The goal was to have a structure with some base members, we can call it a `State node` in State machine, from which the user can add their own custom data on top, without using inheritance or dynamic casts. Would like the collection of different nodes to be stored in a vector in the end.

Obviously, we want to avoid std::vector<SomeType *>

It was suggested I use something like:

class State;
using TransitionHandler = void(*)(State *, const Event &);

template<typename T>
concept StateLike = requires(T s, const Event & e)
{
    { s.onEnter(e) } -> std::same_as<void>;
    { s.onExit(e) }  -> std::same_as<void>;
};

class State final
{
public:
    using StateId = uint32_t;
    StateId id_ = INVALID_ID;
    std::string name_;

    template<typename T>
    requires StateLike<T>
    static State create(std::string name, T & object)
    {
        return State
        {
            name,
            &object,
            [](State * state, const Event & e)
            {
                static_cast<T*>(state->instance_)->onEnter(e);
            },
            [](State * state, const Event & e) 
            {
                static_cast<T*>(state->instance_)->onExit(e);
            }
        };
    }

private:
    static constexpr StateId INVALID_ID = static_cast<StateId>(-1);
    void * instance_;                // user defined state

    State(std::string name, void * instance, TransitionHandler enter, TransitionHandler exit);
};

Now, if I understand things correctly, this will indeed allow the user to provide some custom struct/class as a template param when they create a State object and that State object is going to hold a pointer to it. When it is needed, it is going to call the `enter` and `exit` methods through that static cast.

That should indeed allow us to fill a vector with these State objects and circumvent the need for inheritance, but I wonder if it really performs any better. The collection is in contiguous memory when in the vector, so add, remove, and traversal should be fast. However, all the execution of calls on the State object is going to go through the pointer, which means executing methods on a State will not be part of that performance gain from living in contiguous memory.

Assuming I am always holding on to the current state(s) and that we build the state machine with all its states at startup, what have I really gained? Is there any performance increase at all?

I believe we just replaced the vtable cost with our own pointer, which is pretty much the same?


r/cpp • • Aug 01 '26

BeCPP Symposium 2026 - Bryce Adelstein Lelbach - The CUDA C++ Developer's Toolbox

Thumbnail youtu.be
38 Upvotes

r/cpp • • Jul 31 '26

Static Analysis Experiment with Reflection

32 Upvotes

I want to share a little experiment that I made using reflection. It’s a compile-time style checker using C++26 static reflection. It validates the conventions I use in my own projects (the H_ curried callable thing, Mut/Mov/Ref/Cpy qualifier aliases, plus class/namespace naming). Because reflection can’t properly see into uninstantiated templates yet, I had to write a parser for GCC's display_string_of to extract templates, qualifiers, return types, and requires clauses. Given this weakness it's not a particularly production-ready tool. It could be done with a clang-tidy script, but I learned a few things just from trying to answer "Is it possible? What exactly can I inspect right now?". Unfortunately, we don't have code generation yet so there is a bunch of boilerplate that the user needs to write.

The rationale of the conventions (mainly Mut/Mov/Ref/Cpy) is in GUIDELINES.md. The gory implementation details (and my field notes on GCC bugs) are in VIRACOCHA.md.

https://github.com/NotRiemannCousin/Viracocha/blob/master/VIRACOCHA.md


r/cpp • • Jul 31 '26

Interconverting std::function with copyable_function – Arthur O'Dwyer

Thumbnail quuxplusone.github.io
45 Upvotes

The article shows how converting std::function to std::copyable_function (or vice versa) leads to slower performance and increased memory usage each time the conversion occurs.


r/cpp • • Jul 31 '26

ranges and views for stack, queue, and priority_queue

18 Upvotes

I've always felt that exposing iterators for std::stack or std::queue doesn't quite make sense because iterating over them would typically change their state.

That said, the range features introduced in C++20/23 are just too tempting. 😄

I bet many C++ developers have had this thought at least once:

queue | views::values | views::to<std::vector>()

...or more generally, "What if I could use the ranges pipeline directly on a queue or stack?"

So I spent some time experimenting to see if I could make it work. Here's what I came up with.

https://cognosnotes.com/blog/cpp-pop-range

Edited:

An upgraded version is introduced at https://cognosnotes.com/blog/cpp-pop-range-addendum

Thank you u/SirClueless for the great advice.


r/cpp • • Jul 29 '26

const_cast: A Necessary Evil

Thumbnail elbeno.com
70 Upvotes