아래와 같은 방법으로 이번에는 gcc를 사용해 32bit dll을 생성해 자바파일에서 loadLibrary로 호출하는 경우,
http://huammmm1.tistory.com/446
다음과 같은 에러가 발생 한다.
Exception in thread "main" java.lang.UnsatisfiedLinkError: 문제가 발생한 함수 명(Native Method)
보통 java.lang.UnsatisfiedLinkError는 내가 load하려는 dll파일을 jvm이 찾지 못해서 발생하는 경우가 일반적인데,
이 경우에는 로드하려는 dll은 정상적으로 찾았으나 이상하게도 내부의 native 함수를 찾지 못해서(?) 발생하는 에러
이다.
해결 방법 :
gcc의 입력옵션에 -Wl,--export-all-symbols -Wl,--add-stdcall-alias -m32 을 추가해주면 된다.
ex)
gcc -Wl,--export-all-symbols -Wl,--add-stdcall-alias -m32 -shared -o filename.dll filename.o
* W 옆에 l은 소문자 엘이다.
* Wl,xxx 옵션은 콤마로 구분되어지는 옵션들을 linker에게 인수로 전달한다.
* 즉 위의 옵션에서는 linker에게 --export-all-symbols와 --add-stdcall-alias를 인수로 전달하라는 의미가 된다.
참고)
--export-all-symbols 옵션에 대한 설명 :
Treat all global and weak defined symbols found in the input object files as symbols to be exported. There is a small list of symbols which are not exported by default; see the --no-default-excludes option. You may add to the list of symbols to not export by using the --exclude-symbols option.
--add-stdcall-alias 옵션에 대한 설명 :
Specifies that when dlltool is creating the exports file it should add aliases for stdcall symbols without @ <number> in addition to the symbols with @ <number>.
'Java > 공개글' 카테고리의 다른 글
자바는 call-by-value? call-by-reference? (0) | 2014.11.12 |
---|---|
오류: 기본 클래스 을(를) 찾거나 로드할 수 없습니다. (23) | 2014.11.03 |
java.lang.unsatisfiedlinkerror no in java.library.path (0) | 2014.08.26 |
자바에서 인라인 어셈블리를 해보자 (2) | 2014.07.22 |
Can't load IA 32-bit .dll on a AMD 64-bit platform (1) | 2014.07.22 |