2011-11-15 6 views
4

JavaSE-1.6을 사용하여 Suse Linux 11에 Java 프로그램을 작성하고 javac를 사용하여 빌드하는 데 문제가 있습니다.Linux에서 Java 코드에서 C 함수를 호출하는 방법

나는

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html

에 대한 자습서를 따라하고 지금까지 다음 쓴 :

/usr/lib/gcc/i586-suse-linux/4.3/../../../crt1.o: in function '_start': 
/usr/src/packages/BUILD/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to 'main' 
/tmp/cc97kcJu.o:(.data+0x28) undefined reference to 'hidden alias for int com::ctest::CTest::testCall()' 
/tmp/cc97kcJu.o:(.data+0x74) undefined reference to 'hidden alias for int com::ctest::CTest::testCall()' 
collect2: ld returned 1 exit status 
: 나는 javac의의 CTest.java을 실행하면

package com.ctest; 

class CTest 
{ 
    // Native method declaration 
    native int testCall(); 

    // Load the library 
    static 
    { 
     System.loadLibrary("fpdpReaderLib"); 
    } 

    public static void main(String args[]) 
    { 
     int retVal; 

     // Create class instance 
     CTest cLangTest = new CTest(); 

     // Call native method 
     retVal = cLangTest.testCall(); 

     System.out.println(retVal); 
    } 
} 

내가 오류가 발생을

자바 버전이 아닌 gcc를 사용하고있는 것으로 의심됩니다. javac하지만 확실하지 않습니다.

어떤 아이디어가 될 수 있습니까?

내가 여기에 언급 된 "--main ="옵션을 사용하여 시도했다 :

http://gcc.gnu.org/java/faq.html#4_1

대신 오류로 지금 막 도착하기 전에 :

/tmp/ccwfugWq.o:(.data+0x28) undefined reference to 'hidden alias for int com::ctest::CTest::testCall()' 
/tmp/ccwfugWq.o:(.data+0x74) undefined reference to 'hidden alias for int com::ctest::CTest::testCall()' 
collect2: ld returned 1 exit status 

답변

0

을 당신이해야한다고 생각 gcc javac 컴파일러를 사용하는 대신 Sun Java SDK를 설치하고 사용하십시오.

Google의 경우 suse javac gcc은 비슷한 문제가 발생하며 항상 해결책은 Sun JDK를 사용하는 것으로 보입니다.

+0

감사합니다. JDK가 망가져 버렸습니다. 이제 다시 설치 했으므로 경로가 수정되어 아무런 문제없이 javac을 실행할 수 있습니다. 이제 javah가 내 헤더 파일을 올바르게 작성했습니다. –

1

which javac을 실행하여 사용중인 컴파일러를 결정하는 것이 좋습니다. 자바 6을 원하면 gcj를 사용할 수 없다.

The library containing the native code implementation is loaded by a call to System.loadLibrary(). Placing this call in a static initializer ensures this library is only loaded once per class. The library can be loaded outside of the static block if your application requires it. You might need to configure your environment so the loadLibrary method can find your native code library.

내 중점을 : 당신은 당신이 인용 한 페이지에서

2

JDK 6에서 javac를 사용했다, 그래서 당신은 당신에게 경로를 수정해야합니다. LD_LIBRARY_PATH (또는 무엇이든지간에)를 시스템에 설정 했습니까?

+0

고마워, 내 JDK가 엉망이되어 버렸어. 이제 다시 설치 했어. 경로가 고쳐 졌어. 문제없이 javac을 돌릴 수 있고 javah가 내 헤더 파일을 올바르게 만들었다. –

관련 문제