You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在C++项目中使用Keccak库及SHAKE128函数时遇到问题求助

Troubleshooting SHAKE128 Function Calls from the Keccak Library

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
  • -I tells the compiler where to look for .h files
  • -L points to the directory holding libkeccak.a
  • -lkeccak links against the static library (note we omit the lib prefix 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.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:51:12