Skip to main content
23 votes
Accepted

Fast Hankel Function in Mathematica

This is LibraryLink code with compiler and linker options specifically for macos on Apple Silicon. These are the prerequisites to compile and run this successfully: XCode installed along with the ...
Henrik Schumacher's user avatar
22 votes

Multiplayer game in Mathematica: how to communicate between kernels?

Thanks to the new Channel functionality in Mathematica 11, it is now easy to make (basic) multiplayer games with Mathematica! To demonstrate, I'll modify my hex ...
C. E.'s user avatar
  • 71k
19 votes

What is the complete list of valid FrontEnd Packet types?

I thought I'd keep a running tally of what I know about these packets (excluding the obvious ones like CreatePalettePacket) just for reference. Text / Box ...
19 votes

Minimal effort method for integrating C++ functions into Mathematica

In terms of loading C++ functions, I would strongly suggest LibraryLink. It is a great tool except that it requires you to write sometimes intimidating C code. To make LibraryLink easier to use, I ...
njpipeorgan's user avatar
  • 1,176
16 votes

Can Mathematica edit large binary files in-place?

We can do it straightforward in Java using JLink: ...
BlacKow's user avatar
  • 6,438
14 votes
Accepted

C++ interface to large project

This cannot be answered very well without knowing your C++ library much better. As you said, you have a choice between MathLink and LibraryLink. Generally, I recommend LibraryLink because: It runs ...
Szabolcs's user avatar
  • 236k
12 votes
Accepted

Why does LinkRead block when LinkReadyQ returns True?

Sorry, it turns out there's a fairly critical omission in the documentation. LinkReadyQ, and its C cousins WSReady and ...
John Fultz's user avatar
  • 12.6k
11 votes

Can you trigger update of Dynamic elements from a LinkedLibrary?

Preface I will give a complete solution that shows how a dynamic file watcher can be implemented in Mathematica. The file watcher will track the size of the file and when it changes automatically ...
halirutan's user avatar
  • 113k
11 votes

Callable interface

You should not test pairs of graphs for isomorphism, as that is quadratic in the number of graphs, and it's hopeless. You should compute a canonical labelling of each graph with a suitable library (...
Szabolcs's user avatar
  • 236k
10 votes
Accepted

What is the correct path to add a camera driver?

After 2 years of research and posting this question in other sites, the answer is that although Mathematica (Windows) detects the Camera device, only imaging devices using the Windows video image ...
Jose Enrique Calderon's user avatar
10 votes

How to return escaped characters from MathLink?

halirutan's answer is correct, but more could be said on the matter, so I'll expand. First, MathLink/WSTP has no knowledge about the long-name form of various characters. The only Wolfram Language ...
John Fultz's user avatar
  • 12.6k
9 votes

Write C/C++ programs calling Mathematica functions

The other answers ignore that you are asking about C or C++ (not C# or Java!) Mathematica can be called from C (or C++) through the MathLink interface (recently renamed to WSTP). To learn it, I ...
Szabolcs's user avatar
  • 236k
9 votes
Accepted

WSTP simplifying expression from C

You are not evaluating FullSimplify[(a + a + a + a - b)] You are evaluating FullSimplify["(a + a + a + a - b)"] You used ...
Szabolcs's user avatar
  • 236k
9 votes

Link server WSTP API feature not receiving incoming connections

You are missing just one bit of secret sauce to get this to work. When you connect to a LinkServer link directly using WSTP/MathLink functionality, you need to use "-linkoptions 4" in the arguments to ...
Todd Gayley's user avatar
  • 4,208
7 votes

How to use Mathematica functions in Python programs?

As yet another solution, you can use a new package called PJLink which implements JLink for python. Once you have the package installed you start a KernelLink ...
b3m2a1's user avatar
  • 47k
7 votes

Write C/C++ programs calling Mathematica functions

C Style To Call Mathematica functions from C/C++ you need to use ML_ or WS_ functions. ...
Neel Basu's user avatar
  • 971
7 votes
Accepted

Creating a persistent WSTP application

There are a number of misunderstandings in your question. The C++ application then terminates, though the WSTP link can be left installed, which speeds things up if wstpfunction[] is called again. ...
Szabolcs's user avatar
  • 236k
7 votes

Can Mathematica edit large binary files in-place?

I have noticed that NETLink does not get a lot of love on this site (at least not as much as JLink does), so let me just post ...
RunnyKine's user avatar
  • 33.2k
7 votes

Control a Mathematica kernel from the front-end and from python

For this I'll make use of a little thing I recently wrote to answer a much deeper question: Control Front End in "mathlink" mode The heart of this will be a little package to make a kernel ...
b3m2a1's user avatar
  • 47k
7 votes

How to send packed array from math kernel to 3rd party app via WSTP

Following a dedicated discussion with @Szabolcs, very helpful comments from @ihojnicki, and information from an old thread, I successfully implemented NumPy array sender/receiver in PyWSTP. Assume we ...
kh40tika's user avatar
  • 684
6 votes
Accepted

Wrapping a C library with a streaming interface

You can use MathLink (recently called WSTP) for this. MathLink is an interprocess communication protocol. You can create links and send arbitrary Mathematica expressions through it. This is the ...
Szabolcs's user avatar
  • 236k
6 votes
Accepted

How return an object of a struct from c to Mathematica?

In file.tm, you need to set the return type to Manual, and declare your C(++) function to be void. Then return each piece of ...
Szabolcs's user avatar
  • 236k
6 votes
Accepted

MathLink: How to change the default listening IP address?

Use the undocumented LinkHost option, e.g.: LinkCreate[LinkProtocol -> "TCPIP", LinkHost -> "127.0.0.1"] yields: ...
sakra's user avatar
  • 5,230
6 votes
Accepted

MathLink: What is the difference between MLPutNext and MLPutType?

XXPutNext is XXPutType. I'm pretty certain XXPutNext exists only for backwards ...
ihojnicki's user avatar
  • 3,196
5 votes
Accepted

Using GNU Make to compile MathLink program automatically removes a file

It's a feature of make, see the manual for Chains of Implicit Rules. Intermediate files are remade using their rules just like all other files. But ...
ilian's user avatar
  • 25.5k
5 votes

Control Front End in "mathlink" mode

With Custom REPL & Access to Kernel From Outside Process Non-Blocking Version Update There were issues with the front-end somehow (I really have no idea how) accessing the kernel outside of the ...
b3m2a1's user avatar
  • 47k
5 votes

Returning multiple results from a LibraryLink function

Motivation I was inspired by the discussion in this thread to investigate using JSON to return multiple data types in a single LibraryLink call. I'm posting this ...
Jason B.'s user avatar
  • 69.7k
5 votes

Correct way to handle mysterious NaN` result from MathLink function

This perhaps more of a comment than an answer, but I'm putting it in answer form so it will have more visibility. The IEEE NaN number is not supposed to existing in the WL. That value is represented ...
Itai Seggev's user avatar
  • 14.2k
5 votes
Accepted

Hide WSTP application from taskbar

Turns out it was really simple and Szabolcs was right - removing the line if (!WSInitializeIcon(hinstCurrent, nCmdShow)) return 1; from the ...
mjayvizzle's user avatar
5 votes

Link server WSTP API feature not receiving incoming connections

This is unfortunately not a solution to the main problem yet, but I spent way to much time to not share the information. I tried several different ways and finally gave up. I created a public ...
halirutan's user avatar
  • 113k

Only top scored, non community-wiki answers of a minimum length are eligible