2009-07-30 8 views
1

나는 dhcpctl 라이브러리를 JNA를 사용하여 Java에 바인딩하려고합니다. 원격 DHCP 서버를 호출하는 omapi에게 라이브러리를 사용JNA 정의되지 않은 기호

package com.abiquo.abicloud.omapi; 

import com.abiquo.abicloud.omapi.DHCPControlStructure.DHCPCtrlDataString; 
import com.abiquo.abicloud.omapi.DHCPControlStructure.DHCPHandle; 
import com.abiquo.abicloud.omapi.OmapiControlStructure.OmapiObjectTypeT; 
import com.sun.jna.Library; 
import com.sun.jna.Native; 
import com.sun.jna.Pointer; 

/** 
* Binding of the dhcpctl header. 
* @author [email protected] 
*/ 
public interface DHCPControlLibrary extends Library 
{ 
    /** 
    * Create the loaded instance of the native library 
    */ 
    DHCPControlLibrary INSTANCE = 
     (DHCPControlLibrary) Native.loadLibrary("dhcpctl", DHCPControlLibrary.class); 

    /** 
    * Define as synchronized 
    */ 
    DHCPControlLibrary SYNC_INSTANCE=(DHCPControlLibrary)        Native.synchronizedLibrary(INSTANCE); 

    int dhcpctl_initialize(); 
    int dhcpctl_connect (DHCPHandle handle1, String address, int port, DHCPHandle.ByValue handle2); 
    int dhcpctl_wait_for_completion (DHCPHandle handle, Pointer int1); 
    int dhcpctl_get_value (DHCPCtrlDataString dataString , DHCPHandle.ByValue handleValue, String str1); 
    int dhcpctl_get_boolean (Pointer int1, DHCPHandle.ByValue handleValue, String str1); 
    int dhcpctl_set_value (DHCPHandle.ByValue handleValue, DHCPCtrlDataString dataString, String str1); 
    ... etc ... 

} 

dhcpctl : 이것은 (아직 모든 기능을 선언하지 않았다) 마일 코드입니다. 내가 함께 라이브러리를로드 할 때, :

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'dhcpctl': /usr/lib/libdhcpctl.so: undefined symbol: omapi_type_generic 
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:160) 
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:228) 
    at com.sun.jna.Library$Handler.<init>(Library.java:140) 
    at com.sun.jna.Native.loadLibrary(Native.java:372) 
    at com.sun.jna.Native.loadLibrary(Native.java:357) 
    at com.abiquo.abicloud.omapi.DHCPControlLibrary.<clinit>(DHCPControlLibrary.java:40) 
    at com.abiquo.abicloud.omapi.DHCPexecution.main(DHCPexecution.java:11) 

omapi__type__generic이 omapi.h에 저장된 외부 변수 :

DHCPControlLibrary dhcpExecutor = DHCPControlLibrary.INSTANCE; 

다음과 같은 오류가 발생합니다. 라이브러리를로드 할 때 일종의 링크를해야한다고 생각하지만 어떻게해야할지 모르겠다.

감사합니다.

답변

1

omapi_type_generic은 "omap.h에 저장된 외부 변수"가 아닙니다.

이 변수는 일부 .c 파일에서 어딘가에 정의되어야하며 따라서 일부 .so 또는 .a 파일에 정의되어야합니다.

.c 파일에 정의되어 있지 않으면 바로 거기에 문제가있는 것입니다. 그 이유를 알아 내서 수정하고이 예외를 극복해야합니다.

0

대부분의 경우 omapi 라이브러리를 명시 적으로로드하거나 LD_LIBRARY_PATH에 있는지 확인해야 시스템에서 dhcpctl 라이브러리가로드 될 때 자동으로 찾을 수 있습니다.

0

저는 C++ 코드를 작성하는 동안 extern "C"를 잊어 버렸습니다. 내 경우 C에서 ++ 코드 :

#include <stdlib.h> 
    #include <iostream> 
    using namespace std; 
    extern "C" 
    { 
     void test() { 
      cout << "TEST" << endl; 
     } 

     int addTest(int a,int b) 
     { 
      int c = a + b ; 
      return c ; 
     } 
    } 

및 자바 코드는

import com.sun.jna.Library; 
    import com.sun.jna.Native; 

    public class jnatest1 { 

     public interface Clibrary extends Library { 
      Clibrary INSTANTCE = (Clibrary) Native.loadLibrary("hello", 
        Clibrary.class); 

      void test(); 
      int addTest(int a,int b);  
     } 

     public static void main(String[] args) { 
      Clibrary.INSTANTCE.test(); 
      int c = Clibrary.INSTANTCE.addTest(10,20);  
      System.out.println(c); 
     } 
    } 

그것은 나를

를 작동
관련 문제