gpt4 book ai didi

java - 即使在添加 def 后,外部 "C"也会给出错误 "Linkage specification is not allowed"。在头文件中?

转载 作者:太空宇宙 更新时间:2023-11-04 13:32:00 25 4
gpt4 key购买 nike

这是我的 main.cpp 文件中的代码:

extern "C" JNIEXPORT jint JNICALL Java_SomefnHandling_Jni_1someInit (JNIEnv * env, jobject , jstring var1, jstring var2)
{
//rest part of code in here
}

这是我的 main.h 文件中的定义:

#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Java_Someufnhandling_Jni_1someInit
(JNIEnv *, jobject, jstring, jstring);

#ifdef __cplusplus
}
#endif

这个程序从 java 文件中获取 2 个参数并使用 jni 接口(interface)传递到我的 dll 但在这个文件中我收到错误:

Linkage specification is not allowed

我正在使用 VC++ 生成 DLL 文件,并试图从 SO 中找到相同的解决方案,但他们都提到只是添加 def。在你的头文件中。即使这样做之后,错误仍然存​​在。有什么想法吗?

最佳答案

我删除了我在 main 函数中调用的方法并将它放在 main 之外,它开始像魅力一样工作

关于java - 即使在添加 def 后,外部 "C"也会给出错误 "Linkage specification is not allowed"。在头文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31050199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com