在C++项目中使用Keccak库及SHAKE128函数时遇到问题求助
Hey there! Let’s walk through the most common issues that might be stopping you from calling SHAKE128 properly, and fix them step by step:
1. Make Sure the Compiler Can Find Your Headers
You’ve included SimpleFIPS202.h, but your compiler needs explicit directions to locate that header folder. If you’re using GCC or Clang, add the header path with the -I flag when compiling. For example:
gcc your_source_code.c -I/path/to/libkeccak.a.headers -L/path/to/libkeccak.a -lkeccak -o your_program
-Itells the compiler where to look for.hfiles-Lpoints to the directory holdinglibkeccak.a-lkeccaklinks against the static library (note we omit thelibprefix here)
2. Double-Check Function Signature Matches
Open SimpleFIPS202.h and verify the SHAKE128 function declaration matches exactly how you’re calling it. Even small mismatches (like using int instead of size_t for length parameters, or missing const qualifiers) can break things. The standard SHAKE128 signature looks like this:
void shake128(unsigned char *output, size_t outlen, const unsigned char *input, size_t inlen);
Make sure your code’s call aligns with this.
3. Confirm SHAKE128 Is Actually in the Static Library
It’s possible the libkeccak.a wasn’t compiled with SHAKE128 support enabled. To check if the symbol exists, use nm (Linux/macOS) or dumpbin (Windows):
nm libkeccak.a | grep shake128
If you get no output or an "undefined" marker, the library doesn’t include SHAKE128. You’ll need to recompile the Keccak library with flags that enable SHAKE functions—check the library’s build docs for options like ENABLE_SHAKE.
4. Fix Linker Order Issues
Linkers process libraries in the order you list them. Always put your source files before the library flags, otherwise the linker might miss the function calls it needs to resolve. For example:
❌ This might fail:
gcc -L/path/to/lib -lkeccak your_source_code.c -o your_program
✅ This should work:
gcc your_source_code.c -L/path/to/lib -lkeccak -o your_program
5. Handle Name Mangling (If You’re Using C++)
If this is a C++ project, wrap the header inclusion in an extern "C" block to prevent C++ name mangling—this keeps the linker from looking for mangled C++ symbols instead of the plain C functions from the Keccak library:
extern "C" { #include "SimpleFIPS202.h" }
内容的提问来源于stack exchange,提问作者Raphael D.

