ABI / Memory allocator incompatibility
Crypto++ is primarily tested with Visual C++ and GCC, but less so with Embarcadero.
SecByteBlock
internally uses AlignedAllocate
/AlignedDeallocate
, which can behave differently depending on compiler conventions for memory alignment and operator new/delete
.
If you link Crypto++ as a static lib that was built with a different runtime (RTL) or allocator settings than your project, you’ll often get access violations.
Runtime library mismatch
Check that both Crypto++ and your application are built against the same C++ runtime library (e.g. “Multi-threaded DLL” vs “Multi-threaded static”).
If not: crashes are guaranteed.
Name mangling / exception handling differences
Embarcadero uses its own C++ ABI. If Crypto++ was compiled with an incompatible ABI (for example clang or mingw, then linked into Builder), it will break.
You must ensure it’s built with the same compiler and the same flags.
Memory alignment issues
SecByteBlock
often requests 16-byte aligned memory (for SSE/AVX). If the compiler doesn’t handle that correctly, you’ll see access violations.
Some Builder versions have known issues with alignment.
Embed Crypto++ directly into your project
Instead of linking as a static library, add the Crypto++ source files (*.cpp) directly into your C++ Builder project. That way it shares the same runtime, allocator, and ABI → many problems go away.
Check RTTI and exceptions
C++ Builder sometimes uses different exception mechanisms. Make sure RTTI and exceptions are consistently enabled.
Align build settings
Same runtime library (e.g. Multi-threaded Debug DLL or the static variant)
Same compiler options for memory/alignment
Alternative: build Crypto++ as a DLL
If static linking keeps failing, build Crypto++ as a DLL, export only the API you need, and use it that way. This reduces ABI coupling.
--
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cryptopp-users/dda6224f-5905-43b4-b93c-da3878027471n%40googlegroups.com.
way to use Crypto++ with Embarcadero C++ Builder and avoid the SecByteBlock
access-violation problems.
Get the Crypto++ sources
Download the official Crypto++ source tree (zip / tarball or clone the repo). Don’t use a prebuilt .lib
made by MSVC/GCC — that causes ABI/allocator mismatches.
Open your C++ Builder project / create one
Select the correct target (Win32 or Win64). Make sure your app target is the platform you intend to test.
Add Crypto++ include path
Project → Options → C++ Compiler → Include path (Search path) → add the Crypto++ folder that contains the headers (so #include <cryptopp/secblock.h>
resolves).
Add Crypto++ .cpp files to your project
Right-click the project → Add → Add existing files → select all .cpp
files from the Crypto++ src
folder excepttest/bench files (e.g. exclude test.cpp
, bench.cpp
, validat*.cpp
, samples).
Why: compiling the sources inside your project forces Crypto++ to use the same compiler, runtime and allocator as your app.
Set conditional define (optional but recommended if you see crashes)
Project → Options → C++ Compiler → Conditional defines → add:CRYPTOPP_DISABLE_ASM
This disables assembly/ASM acceleration and can avoid alignment/ASM compatibility issues with some Builder toolchain versions. Try without it first — if crashes persist, enable this define and rebuild.
Compiler / runtime settings to check
Make sure your project target (Win32/Win64) is the same for all files.
Keep C++ exceptions enabled (default).
If you later build Crypto++ as a separate DLL, ensure both DLL and EXE use the same Link with dynamic RTL / Use runtime packages setting. Mismatched runtime package/Dynamic RTL settings cause problems.
Build (Clean + Build)
Do a full clean and rebuild the project so all Crypto++ .cpp files are compiled by C++ Builder.
Simple test program
Paste this small test into your project to validate SecByteBlock
usage:
cpp#include <iostream> #include <cryptopp/secblock.h> using CryptoPP::SecByteBlock; int main() { SecByteBlock sb(32); for (size_t i = 0; i < sb.size(); ++i) sb[i] = static_cast<unsigned char>(i); std::cout << "sb[0] = " << int(sb[0]) << std::endl; return 0; }
Run this under the debugger — if it runs and prints, SecByteBlock
is working.
If problems remain
Ensure you didn’t accidentally link any precompiled Crypto++ libs from other compilers.
Confirm Win32 vs Win64 mismatch is not present.
Enable CRYPTOPP_DISABLE_ASM
and rebuild.
As a fallback, build Crypto++ as a C++ Builder DLL (add sources to a DLL project) and ensure both DLL and EXE use the same dynamic RTL/runtime-packages setting.
Do not link a Crypto++ library built with MSVC/GCC into a C++ Builder app — compile the Crypto++ sources with Embarcadero (add the
.cpp
files to your Builder project) or build Crypto++ with the Builder compiler (or as a Builder DLL). If you see alignment crashes, try-DCRYPTOPP_DISABLE_ASM
and make sure Win32/Win64 and runtime (dynamic RTL / runtime packages) settings match.