I have a problem running my test program on linux. I want to connect to mathematica kernel using java API. On windows, I put both jlink.jar and JLinkNativeLibrary.dll next to my executable file, let's say test.jar, and it works well. However, doing same on Linux machine, gives me error "cannot find the required native library named JLinkNativeLibrary". Please help me if you know. This is my code :

        //String s = "-linkmode launch -linkname 'E:\\Software\\mathematica\\mathkernel.exe'"; // This is Windows version
        String s = "-linkmode launch -linkname math -mathlink ";
        ml = MathLinkFactory.createKernelLink(s);
        String answer = ml.evaluateToOutputForm("2 + 3",0);

Ps: Is this way to connect to math kernel on Linux is correct? I found it on Wolfram documents.

  • $\begingroup$ For Ubuntu 22.04, try /usr/local/Wolfram/Mathematica/13.2/SystemFiles/Links/JLink/SystemFiles/Libraries/Linux-x86-64/libJLinkNativeLibrary.so. Not a dll, but should be equivalent. $\endgroup$
    – user87932
    May 4, 2023 at 19:31
  • $\begingroup$ I tried this file. But still get the same error. the point is the error says "library named JLinkNativeLibrary" but the linux file is "lib" + "JLinkNativeLibrary". i even tried to rename the .so file but does not work. I added to export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: $HOME/fx_tool/ but cannot find it yet $\endgroup$
    – Azzurro94
    May 4, 2023 at 19:35
  • $\begingroup$ I'm a bit confused then. It looks like you're trying to use JLink with MathLink, but these are separate things. MathLink is generally used when you want to interface Mathematica to C/C++ code, JLink is an entirely separate thing. I'd recommend looking at the JLink tutorial in the documentation, and proceed from there. JLink basically interfaces to the kernel, and handles the link internally, so no extra MathLink code should be needed. The JLink tutorial does include a section on using JLink in conjunction with MathLink, so perhaps that's what you need to look at. $\endgroup$
    – user87932
    May 4, 2023 at 19:43

1 Answer 1


Ok I could find the solution after lots of try and search. Two points are here:
first, in the argument it must be 'math -mathlink', I forgot the ' '. However, it does not work again. So, I tried to use same approach like windows, I put the absolute path for MathKernel executable program on Linux server. something like this:

 String s = "-linkmode launch -linkname 'YOUR_PATH_TO_MATHEMATICA/mathematica/13.2.1/Executables/MathKernel' ";
 ml = MathLinkFactory.createKernelLink(s);

Now it returns 5, as it should. thanks


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.