2015-02-04 4 views
2

을 받고, Windows에서 꿀꺽 꿀꺽를 사용하여 ++ 코드 :호출 C++ 기능 나는이 C가 java.lang.UnsatisfiedLinkError가

/* File : example.cpp */ 
#include <iostream> 
#include <time.h> 

double My_variable = 3.0; 

int fact(int n) { 
if (n <= 1) return 1; 
else return n*fact(n-1); 
} 

int my_mod(int x, int y) { 
return (x%y); 
} 

char *get_time() 
{ 
time_t ltime; 
time(&ltime); 
return ctime(&ltime); 
}   

나는이 .I 코드가 있습니다

/* example.i */ 
%module example 
%{ 
/* Put header files here or function declarations like below */ 
extern double My_variable; 
extern int fact(int n); 
extern int my_mod(int x, int y); 
extern char *get_time(); 
%} 

extern double My_variable; 
extern int fact(int n); 
extern int my_mod(int x, int y); 
extern char *get_time(); 

내가 노력하고를 java 내부에서 이러한 함수를 호출합니다. 그래서 윈도우 7 (밍와 함께) cmd를 내가 할 :

swig -c++ -java example.i 
g++ -c example.cpp example_wrap.cxx -I "C:\Program Files (x86)\Java\jdk1.8.0_31\include" -I "C:\Program Files (x86)\Java\jdk1.8.0_31\include\win32" 
g++ -shared example.o example_wrap.o -o example.dll -I "C:\Program Files (x86)\Java\jdk1.8.0_31\include" -I "C:\Program Files (x86)\Java\jdk1.8.0_31\include\win32" 

이것은 dll 파일을 만듭니다. 지금은 다음과 같은 자바 프로그램을 실행하려고 :

public class main { 
    public static void main(String argv[]) { 
    System.loadLibrary("example"); 
    System.out.println(example.fact(5)); 
    System.out.println(example.get_time()); 
    } 
} 

그래서 내가 도망을

javac main.java 

그것은 잘 컴파일,하지만 난

java main 

을 사용하여 실행 때이 오류가 발생합니다 :

Exception in thread "main" java.lang.UnsatisfiedLinkError:  exampleJNI.fact(I)I 
     at exampleJNI.fact(Native Method) 
     at example.fact(example.java:20) 
     at main.main(main.java:4) 

무엇이 문제입니까?

+0

-Djava.library.path = 을 사용하여 java를 호출해야합니다. 참조 : http://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-use/ –

+0

안녕하세요. 회신 해 주셔서 감사합니다. 그러나 그런 식으로는 작동하지 않습니다. 같은 오류가 발생합니다. 실제로 java는 dll을 찾아서로드하지만 그 이후에는 무엇이 잘못되는지 알지 못합니다. 자바가 dll을 찾지 못하면 다음과 같은 내용을 줄 것이다 : "스레드"main "에서 예외"main "java.lang.UnsatisfiedLinkError : java.lang에없는 예제 brary.path at java.lang.ClassLoader. loadLibrary (알 수없는 소스) java.lang.Runtime.loadLibrary0 (알 수없는 소스) java.lang.System.loadLibrary (알 수없는 소스) at main.main (main.java:3) " – Bob

+0

다른 옵션은 귀하의 DLL을 찾을 수없는 무언가를 찾을 수 있습니다 .... 체크 아웃은 2.2에 의존합니다. 어떤 의존성이 없는지 알려줄 것입니다. –

답변

0

문제는 의견을

-Wl,--kill-at 

감사를 사용하여 해결했다.