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

Android使用pHash生成图片哈希时ulong64类型解析错误解决咨询

Fixing "cannot resolve type ulong64" in Android C with pHash

When working with pHash's ph_dct_imagehash on Android, the missing ulong64 type is a common hiccup since Android's stdint.h doesn't include it natively. Here are several straightforward solutions to resolve this error:

1. Manually typedef ulong64 using Android's native types

Android's NDK provides uint64_t (a standard 64-bit unsigned integer type) in stdint.h, which is exactly what ulong64 represents in pHash. You can define the type yourself at the top of your C file (or in a shared header) before including pHash headers:

#include <stdint.h>

// Define ulong64 if it's not already defined
#ifndef ulong64
typedef uint64_t ulong64;
#endif

// Now include pHash headers
#include "phash.h"

This tells the compiler to treat ulong64 as an alias for uint64_t, matching pHash's expected type without any external dependencies.

2. Adjust your variable declaration to use uint64_t directly

If you prefer not to add a typedef, you can modify your code to use uint64_t instead of ulong64, and cast it when calling the pHash function. Since ulong64 is just a 64-bit unsigned integer, the cast is safe:

#include <stdint.h>
#include "phash.h"

int main() {
    uint64_t hash_value;
    const char* image_path = "/path/to/your/image.jpg";
    
    // Cast the uint64_t reference to ulong64&
    int result = ph_dct_imagehash(image_path, reinterpret_cast<ulong64&>(hash_value));
    
    if (result == 0) {
        // Hash generated successfully
    }
    return 0;
}

Note: This works because the underlying memory representation of uint64_t and ulong64 is identical on Android architectures.

3. Check if pHash provides its own definition for ulong64

Sometimes pHash's header files include a definition for ulong64 that you might be missing. Double-check that you're including all necessary pHash headers (like phash.h or pHash.h depending on your setup). If the type is defined in a secondary header, make sure to include that as well.

Do you need a third-party library?

Nope! Android's NDK already has all the tools you need to resolve this. You don't need to add any extra libraries—just use the native uint64_t type as shown above.

内容的提问来源于stack exchange,提问作者Sagar Trehan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:26:03