way to use Crypto++ with Embarcadero C++ Builder and avoid the SecByteBlock access-violation problems. Small step-by-step (C++ Builder + Crypto++)
1. *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. 2. *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. 3. *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). 4. *Add Crypto++ .cpp files to your project* Right-click the project → Add → *Add existing files* → select all .cpp files from the Crypto++ src folder *except*test/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. 5. *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. 6. *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. 7. *Build (Clean + Build)* Do a full clean and rebuild the project so all Crypto++ .cpp files are compiled by C++ Builder. 8. *Simple test program* Paste this small test into your project to validate SecByteBlock usage: cpp KopierenBearbeiten #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. 9. *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. ------------------------------ Short one-liner you can paste *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. I hope is helpful have nice day One Sini <ones...@gmail.com> schrieb am Di. 9. Sept. 2025 um 11:07: > Typical causes (especially with C++ Builder + Crypto++) > > *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. > > ------------------------------ > Possible solutions > > - > > *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. > > Have nice day > > William Schwank <syppo...@gmail.com> schrieb am Di. 9. Sept. 2025 um > 01:53: > >> Hello, everyone, I'm a c++ builder user, and tring to use cryptopp with >> c++ builder. >> >> With the lastest version c++ builder, I succ compile and build cryptopp >> to static lib. >> >> However, during using, especially when calling anything invove SecByteBlock, >> the application will just got exited, with errors like Access violation >> at address 00E87383 in module xxX. >> >> Does any has a clue and succ use this lib with c++ builder? I know this >> tool has only a very small group of users. >> >> -- >> 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-users+unsubscr...@googlegroups.com. >> To view this discussion visit >> https://groups.google.com/d/msgid/cryptopp-users/dda6224f-5905-43b4-b93c-da3878027471n%40googlegroups.com >> <https://groups.google.com/d/msgid/cryptopp-users/dda6224f-5905-43b4-b93c-da3878027471n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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-users+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/cryptopp-users/CAJm61-BkJG142Dhiv1pF5cmXyug66qewxzR0S2wE_VP0v6XJMA%40mail.gmail.com.