diff --git a/.github/include/windows/jni_md.h b/.github/include/windows/jni_md.h index 6c8d6b9e..934ffb18 100644 --- a/.github/include/windows/jni_md.h +++ b/.github/include/windows/jni_md.h @@ -26,13 +26,26 @@ #ifndef _JAVASOFT_JNI_MD_H_ #define _JAVASOFT_JNI_MD_H_ -#define JNIEXPORT __declspec(dllexport) -#define JNIIMPORT __declspec(dllimport) -#define JNICALL __stdcall +#ifdef _MSC_VER + // Windows + MSVC 编译器 + #define JNIEXPORT __declspec(dllexport) + #define JNIIMPORT __declspec(dllimport) + #define JNICALL __stdcall +#else + // 其他平台或非 MSVC 编译器 + #define JNIEXPORT + #define JNIIMPORT + #define JNICALL +#endif // 'long' is always 32 bit on windows so this matches what jdk expects typedef long jint; -typedef __int64 jlong; +#ifdef PLATFORM_WINDOWS + typedef __int64 jlong; +#else + #include + typedef int64_t jlong; +#endif typedef signed char jbyte; #endif /* !_JAVASOFT_JNI_MD_H_ */ diff --git a/CMakeLists.txt b/CMakeLists.txt index 96c62950..bc901bd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,3 +119,9 @@ if (LLAMA_METAL AND NOT LLAMA_METAL_EMBED_LIBRARY) # copy ggml-common.h and ggml-metal.metal to bin directory configure_file(${llama.cpp_SOURCE_DIR}/ggml-metal.metal ${JLLAMA_DIR}/ggml-metal.metal COPYONLY) endif() + +if (MSVC) + add_definitions(-DPLATFORM_WINDOWS) +else() + add_definitions(-DPLATFORM_UNIX) +endif() \ No newline at end of file diff --git a/src/main/cpp/jllama.cpp b/src/main/cpp/jllama.cpp index 11c80ae0..78165c46 100644 --- a/src/main/cpp/jllama.cpp +++ b/src/main/cpp/jllama.cpp @@ -813,7 +813,7 @@ JNIEXPORT void JNICALL Java_de_kherud_llama_LlamaModel_delete(JNIEnv *env, jobje JNIEXPORT void JNICALL Java_de_kherud_llama_LlamaModel_cancelCompletion(JNIEnv *env, jobject obj, jint id_task) { jlong server_handle = env->GetLongField(obj, f_model_pointer); auto *ctx_server = reinterpret_cast(server_handle); // NOLINT(*-no-int-to-ptr) - std::unordered_set id_tasks = {id_task}; + std::unordered_set id_tasks = {static_cast(id_task)}; ctx_server->cancel_tasks(id_tasks); ctx_server->queue_results.remove_waiting_task_id(id_task); }