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:
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"}
PERROR: 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
/MDunless 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/MDflags by hand; Conan's toolchain sets it from the profile. - Don't pass
std::string,std::vectoror 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 newstd::stringABIs can't be mixed (Source, Binaries & ABI). Conan:compiler.libcxx=libstdc++vslibstdc++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.distroviasettings_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:
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?
- For nicer logs
- Conan chooses binaries from the profile; a mismatch links binaries built for another ABI
- CMake reads the profile
- It doesn't matter
What happens when objects built with /MT and /MD are linked together?
- Nothing
- LNK2038 RuntimeLibrary mismatch, or heap corruption across DLL boundaries
- Faster code
- Smaller binaries
Which remote setup prevents dependency confusion best?
- Public remote first
- A single company remote that proxies the public one, with private names prefixed
- Many remotes in random order
- No remotes