tags:

views:

357

answers:

1

Hello,

I'm trying to bind the dhcpctl library to Java using JNA. This is mi code (I didn't declare all the functions yet):

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 uses omapi library to call the remote DHCP server. So, when I try to load the library with:

DHCPControlLibrary dhcpExecutor = DHCPControlLibrary.INSTANCE;

it throws the following error:

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 is an external variable stored in omapi.h. I think I have to do a sort of linking when i load the library, but I don't know how to do it.

Many thanks.

+1  A: 

omapi_type_generic is not "an external variable stored in omap.h".

This variable must be defined in some .c file somewhere and hence in some .so or .a.

If it is not defined in any .c file then there is your problem right there. Find out why it is so and fix it and you should overcome this exception.

hhafez