TExcelTAD
Home › C/C++ Packages: Conan 2, vcpkg & CPM.cmake › Field Notes: ABI, Runtimes & Private Remotes

Field Notes: ABI, Runtimes & Private Remotes

The bugs in this lesson are the expensive kind: they often compile, sometimes link, and then crash or misbehave at run time on one platform. Package managers prevent most of them, but only if their configuration tells the truth about how your code is built.

The profile must describe the real compiler

Conan picks binaries from the profile, not from the compiler it finds on PATH. If the profile says gcc 13 and CMake actually uses clang with libc++, Conan happily hands you libstdc++ binaries and you get link errors full of std::__1:: vs std::__cxx11:: symbols, or worse, subtle ODR violations. Describe the real compiler, and the missing binaries show up immediately and honestly:

bash · try it yourself
conan install --requires=fmt/12.1.0 -nr \
  -s compiler=clang -s compiler.version=18 -s compiler.libcxx=libc++ 2>&1 | grep -E 'Missing binary|No compatible'
echo "--- and make CMake use the same compiler"
cat <<'P'
[settings]
compiler=clang
compiler.version=18
compiler.libcxx=libc++
compiler.cppstd=20

[conf]
tools.build:compiler_executables={"c": "clang-18", "cpp": "clang++-18"}
P
ERROR: Missing binary: fmt/12.1.0:cb30962437aab614773cc1a2e9594406cbe534ed
--- and make CMake use the same compiler
[settings]
compiler=clang
compiler.version=18
compiler.libcxx=libc++
compiler.cppstd=20

[conf]
tools.build:compiler_executables={"c": "clang-18", "cpp": "clang++-18"}

The second half is a profile that keeps both sides consistent: the settings choose the binaries, and tools.build:compiler_executables makes the generated toolchain use the same compiler. The same rule applies to vcpkg: if you change compilers, use a different triplet or let the compiler hash change the ABI hashes; never copy vcpkg_installed/ between machines with different toolchains.

Never mix C runtimes on Windows (MD/MT)

MSVC has four C/C++ runtime variants:

Flag Runtime Conan setting vcpkg
/MD dynamic, release (MSVCP140.dll, ucrtbase.dll) compiler.runtime=dynamic, compiler.runtime_type=Release VCPKG_CRT_LINKAGE dynamic
/MDd dynamic, debug runtime=dynamic, runtime_type=Debug dynamic + Debug build
/MT static, release compiler.runtime=static VCPKG_CRT_LINKAGE static (-static triplets)
/MTd static, debug runtime=static, runtime_type=Debug static + Debug build

Linking objects built with different runtimes gives LNK2038: mismatch detected for 'RuntimeLibrary' if you're lucky, and heap corruption if a DLL boundary hides it (memory allocated by one runtime's heap and freed by another's). Rules:

  • One runtime per process. Pick /MD unless you have a reason not to; it's what most prebuilt binaries use.
  • Debug and Release don't mix on Windows (iterator debugging changes std::vector's layout). Install dependencies per build type.
  • With CMake, set CMAKE_MSVC_RUNTIME_LIBRARY (policy CMP0091, which Conan's presets enable) instead of editing /MD flags by hand; Conan's toolchain sets it from the profile.
  • Don't pass std::string, std::vector or exceptions across DLL boundaries built by different compilers or runtimes; use C interfaces there.

Linux has its own versions of the problem

  • _GLIBCXX_USE_CXX11_ABI: the old and new std::string ABIs can't be mixed (Source, Binaries & ABI). Conan: compiler.libcxx=libstdc++ vs libstdc++11.
  • glibc version: a binary built on a newer distro may need a newer glibc than your target has (version GLIBC_2.38 not found). Build release binaries on the oldest distro you support, or in a container with that glibc. Conan doesn't model the glibc version by default; teams that need it add a custom setting (e.g. os.distro via settings_user.yml).
  • Static vs shared duplicates: two shared libraries that each link a static copy of the same dependency (say, protobuf) can break at run time due to duplicate global state. Prefer one shared copy, or make the dependency private and hidden.

Private remote hygiene

Do Why
Use one remote URL for developers: an Artifactory virtual repo that proxies ConanCenter, or a vcpkg registry + binary cache you control no surprise packages from the public internet, and builds survive upstream outages
Put private remotes first, or disable public ones prevents dependency confusion: a public package squatting your private package's name
Give your packages a prefix or user/channel (acme-crypto, crypto/1.0@acme/stable) collisions with public names become impossible
Separate dev and release repositories, and promote tested packages consumers of release never see untested binaries
Use read-only tokens for developers, write tokens only in CI, rotate them a leaked laptop token can't overwrite packages
Keep recipes/ports in version control and build packages only in CI every binary on the server can be traced to a commit and a log
Turn on retention policies servers fill up with snapshots of every branch otherwise

A runnable model: dependency confusion

Which remote wins depends on order. This model resolves a package name across remotes in order, the way Conan does by default, and shows why a public remote listed first is a risk:

python · try it yourself
remotes = {
    "conancenter": {"fmt": "12.1.0", "acme-crypto": "99.0.0"},   # an attacker published acme-crypto publicly
    "company":     {"acme-crypto": "2.3.1", "acme-logging": "1.4.0"},
    # an Artifactory virtual repo: company packages + a ConanCenter proxy that excludes "acme-*" names
    "virtual":     {"fmt": "12.1.0", "acme-crypto": "2.3.1", "acme-logging": "1.4.0"},
}

def resolve(name, order):
    for remote in order:
        if name in remotes[remote]:
            return f"{name}/{remotes[remote][name]} from {remote}"
    return f"{name}: not found"

for order in (["conancenter", "company"], ["company", "conancenter"], ["virtual"]):
    print(" -> ".join(order))
    for pkg in ("fmt", "acme-crypto", "acme-logging"):
        print("   ", resolve(pkg, order))
conancenter -> company
    fmt/12.1.0 from conancenter
    acme-crypto/99.0.0 from conancenter
    acme-logging/1.4.0 from company
company -> conancenter
    fmt/12.1.0 from conancenter
    acme-crypto/2.3.1 from company
    acme-logging/1.4.0 from company
virtual
    fmt/12.1.0 from virtual
    acme-crypto/2.3.1 from virtual
    acme-logging/1.4.0 from virtual

The first order downloads the attacker's acme-crypto. Putting company first fixes the private names. A single virtual remote that serves company packages and proxies ConanCenter, with the acme-* names excluded from the proxy, fixes them too, and also keeps builds working when the public remote is down.

Test yourself

Why must the Conan profile describe the compiler CMake actually uses?

  1. For nicer logs
  2. Conan chooses binaries from the profile; a mismatch links binaries built for another ABI
  3. CMake reads the profile
  4. It doesn't matter

What happens when objects built with /MT and /MD are linked together?

  1. Nothing
  2. LNK2038 RuntimeLibrary mismatch, or heap corruption across DLL boundaries
  3. Faster code
  4. Smaller binaries

Which remote setup prevents dependency confusion best?

  1. Public remote first
  2. A single company remote that proxies the public one, with private names prefixed
  3. Many remotes in random order
  4. No remotes