JCuda UnsatisfiedLinkError with Netbeans on MacOSX

Hello,

I solved a problem with Jcuda (0.3.1) library with Netbeans (6.9.1) on MacOSX (10.6.4). Despite Jcuda works fine with java called with Terminal, I always get an UnsatisfiedLinkError problem with Netbeans :

Creating input data...
Performing Sgemm with JCublas...
Error while loading native library with base name "JCublas"
Operating system name: Mac OS X
Architecture         : x86_64
Architecture bit size: 64
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load native library
        at jcuda.LibUtils.loadLibrary(LibUtils.java:79)
        at jcuda.jcublas.JCublas.assertInit(JCublas.java:174)
        at jcuda.jcublas.JCublas.cublasInit(JCublas.java:198)
        at cuda.JCublasSample.sgemmJCublas(JCublasSample.java:80)
        at cuda.JCublasSample.testSgemm(JCublasSample.java:62)
        at cuda.JCublasSample.main(JCublasSample.java:41)
Java Result: 1

It seems that Netbeans doesn’t load the user profile (the .profile file in the home directory), therefore if you defined global variables there, the JVM would not be able to run JCuda properly.

One solution is to call Netbeans from Terminal, open Terminal and type :

/Applications/NetBeans/NetBeans\ 6.9.1.app/Contents/MacOS/netbeans

But it is not very practical, I suggest another and permanent solution that consists to modify the launch script of Netbeans to include the profile configuration.

Open (with Textedit) /Applications/NetBeans/NetBeans 6.9.1.app/Contents/Resources/NetBeans/bin/netbeans and just after the copyright add :

# User profile
if [ -f ~/.profile ] ; then
    source ~/.profile
fi

Save and that’s all. You can launch Netbeans from Apps folder only by clicking and JCuda will work fine !

Just for remind, here is my .profile :

# CUDA
export PATH=$PATH:/usr/local/cuda/bin
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/usr/local/cuda/lib64:/usr/local/cuda/lib

# JCUDA
export JCUDA=/JCUDA (the folder that contains Jcuda *.jar and *.jnilib files)
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:$JCUDA
export CLASSPATH=.:$JCUDA/jcublas-0.3.1.jar:$JCUDA/jcuda-0.3.1.jar:$JCUDA/jcudpp-0.3.1.jar:$JCUDA/jcufft-0.3.1.jar

I hope it could be helpful for someone, and sorry for my poor english.

PS: This kind of trips would probably work with Eclipse also.

Hello christux,

Thank you for this information. I’m usually using Eclipse, and don’t have the chance to run own tests on MacOS, so I’m not always aware of such difficulties that users may encounter. (Of course, the „UnsatisfiedLinkError“ is very common, but I don’t even understand what was the reason for this error in the case that you described…).
If users are running into trouble with MacOS and Netbeans, this post may be really helpful for them :slight_smile:

bye
Marco

Dear christux,

I tried to use JCuda with Eclipse on OSX but encountered to the same problem such as:

Creating input data
Initializing device data using JCuda
Error while loading native library with base name “JCudaRuntime”
Operating system name: Mac OS X
Architecture : x86_64
Architecture bit size: 64
Exception in thread “main” java.lang.UnsatisfiedLinkError: Could not load native library
at jcuda.LibUtils.loadLibrary(LibUtils.java:79)
at jcuda.runtime.JCuda.assertInit(JCuda.java:225)
at jcuda.runtime.JCuda.cudaMalloc(JCuda.java:1513)
at cuda.JCudaRuntimeSample.main(JCudaRuntimeSample.java:42)


Do you have any solution to this?

Hello,

Are your global vars set properly in your .profile ?
Are you able to run an example file with java in command line ?
Try to launch Eclipse with terminal : “/Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse”

I doesn’t work unfortunately… still in the same problem…

echo $PATH | grep -q -s “/usr/local/bin”
if [ $? -eq 1 ] ; then
PATH=$PATH:/usr/local/bin
export PATH
fi

CUDA

export PATH=$PATH:/usr/local/cuda/bin
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/usr/local/cuda/lib64:/usr/local/cuda/lib

JCUDA

export JCUDA=/Users/seongkilee/Documents/MyJavaFolder/JavaExternalLibrary/JCuda/JCuda-All-0.3.0a-bin-apple-x86
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:$JCUDA
export CLASSPATH=.:$JCUDA/jcublas-0.3.0a.jar:$JCUDA/jcuda-0.3.0a.jar:$JCUDA/jcudpp-0.3.0a.jar:$JCUDA/jcufft-0.3.0a.jar

We also tried 0.3.1 version…

I see you are using 0.3.0a version on JCuda, I think it doesn’t run in 64 bits.
Try 0.3.1 version or add -d32 tag on the JVM.

Hello,

As christux pointed out, there is currently no MacOS 64 version of JCuda 0.3.0a. (It should in general be possible to compile the native library of version 0.3.0a for 64 bit as well, but it it has not been done yet)

You said that you also tried the 0.3.1 version. There is only the 64bit MacOS version, so this should work on your computer in general. Do you receive the same error message when using the “JCuda-All-0.3.1-bin-apple-x86**_64**.zip”?

bye
Marco

Yes, Marco.

I have the same problem, yet.
I just hope to meet someone who has the same problem and a solution to it…