hard link with java6

152 views
Skip to first unread message

rupert.thurner

unread,
Sep 15, 2011, 3:32:53 AM9/15/11
to Java Native Access
i tried to use jna to create a hard link, which worked on windows xp.
on windows7 it gives an error with the following code:

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

public class Link {
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),
CLibrary.class);
int link(String fromFile, String toFile);
}

public static void main(String args[]) {
CLibrary.INSTANCE.link("jna-3.3.0.jar", "link-to-jna-3.3.0.jar");
}
}

the error is:
C:\tmp\link>java Link
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error
looking up function 'link': The specified procedure could not be
found.

at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:
347)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:
327)
at com.sun.jna.Library$Handler.invoke(Library.java:203)
at $Proxy0.link(Unknown Source)
at Link.main(Link.java:13)

what do i do wrong here?

rupert.

Timothy Wall

unread,
Sep 15, 2011, 7:24:13 AM9/15/11
to jna-...@googlegroups.com
Perhaps the function doesn't exist on windows 7 or is represented by a macro? Look up the corresponding MS Windows documentation for the function -- I believe it's called CreateHardLink, not "link".
Reply all
Reply to author
Forward
0 new messages