这里有一个用C写的lib文件,里面封装了n个函数,还有一份所有函数结构的说明文档,现在要通过JAVA来调用这些函数。实现其功能,具体函数的源文件没有。请问怎么怎么用JAVA调用这些函数?我用JNI实现的时候用VC编译,我是在C文件里直接调用了接口函数。希望各位高手给予指导,或者给指点一下方法,谢谢!在编译过程中报错:
Compiling...
testrcv.cpp
Linking...
   Creating library Debug/testcas.lib and object Debug/testcas.exp
testrcv.obj : error LNK2001: unresolved external symbol "void __cdecl tr_pmsg(char *,int)" (?tr_pmsg@@YAXPADH@Z)
testrcv.obj : error LNK2001: unresolved external symbol "void __cdecl set_format(char *,...)" (?set_format@@YAXPADZZ)
testrcv.obj : error LNK2001: unresolved external symbol "struct ctl_tr_str  Ctl_tr" (?Ctl_tr@@3Uctl_tr_str@@A)
testrcv.obj : error LNK2001: unresolved external symbol "short __cdecl casmf_close(struct cas_gen_str *)" (?casmf_close@@YAFPAUcas_gen_str@@@Z)
testrcv.obj : error LNK2001: unresolved external symbol "short __cdecl casmf_snd(struct cas_gen_str *,char *)" (?casmf_snd@@YAFPAUcas_gen_str@@PAD@Z)
testrcv.obj : error LNK2001: unresolved external symbol "short __cdecl casmf_abort(struct cas_gen_str *)" (?casmf_abort@@YAFPAUcas_gen_str@@@Z)
testrcv.obj : error LNK2001: unresolved external symbol "short __cdecl casmf_rcv(struct cas_gen_str *,char *,int)" (?casmf_rcv@@YAFPAUcas_gen_str@@PADH@Z)
testrcv.obj : error LNK2001: unresolved external symbol "short __cdecl casmf_stop(void)" (?casmf_stop@@YAFXZ)
testrcv.obj : error LNK2001: unresolved external symbol "short __cdecl casmf_open(struct cas_ope_str *,int,int)" (?casmf_open@@YAFPAUcas_ope_str@@HH@Z)
testrcv.obj : error LNK2001: unresolved external symbol "short __cdecl casmf_init(int,char *)" (?casmf_init@@YAFHPAD@Z)
Debug/testcas.dll : fatal error LNK1120: 10 unresolved externals
Error executing link.exe.testcas.dll - 11 error(s), 0 warning(s)
其中报错的都是所要调用的lib里的函数

解决方案 »

  1.   

    你应该先编译c程序为dll把他注册成服务,然后在java程序中调用,unresolved external symbol 的错误JNI  java本地编程接口。是 Java Native Interface 的英文缩写。他能够
    使java 代码与用其他编程语言编写的应用程序和库进行互操作。(其他编程语言大多是 c,c++和汇编语言。)
      

  2.   

    因为是一个lib,是别人提供的一些标准的函数,我要在java里用到这些函数,所以我就想先写一个符合jni标准的dll,去掉用lib里的函数,然后再在java里调用dll。可是我在编译dll的时候,编译可以过,在link的时候报错。而且肯定lib是可以用的,我在c里直接写一个exe文件都可以调用lib,而且正常运行。哪位大虾能帮帮忙,谢谢谢谢……
      

  3.   

    能把你的JAVA调用代码写一下么?