Recently, I discovered that LibraryLink technique is a very useful tool to improve the performance of function. Firstly, I need to use LibraryLink template to write C/C++ program. Then compiling the program to dynamically linked library(i.e. *.dll file) via the CCompilerDriver package and C compiler. Please see this answer.

If there is no error in your code, the compiling process will successful and no error information occurs. Unfortunately, there will always be some errors/bugs in the code in practice. For instance, today I applied a right algorithm to LibraryLink template to calculate the nonzero values of B-spline basis, but I forgot the variable declaration of saved, and misuse the MArgument_setReal() operation.

In this process, I discovered that the debuging is very critical. While the error information that the CreateLibrary[]given is very limitted. Even if the compiling process is smoothly, the bug maybe exists. Please see Update of that question. Although NonzeroBasis[] gives me the result, it is wrong and I cannot debug it to find where the error is.

Thank for Albert Retey and Szabolcs's suggestions 1, 2, so I write a new thread here.

  • If and how it is possible to attach a debugger to such a dynamically linked library on the supported operating systems?
  • 2
    $\begingroup$ The LibraryLink libraries are loaded into the kernel process, so you may attach a debugger to it ($ProcessID can be helpful) and then set a break point in one of your functions. $\endgroup$
    – ilian
    Jun 22, 2016 at 14:53
  • $\begingroup$ Strictly speaking this is not a Mathematica question. It is about handling debuggers. Yet I think it's still a very important question to ask on this site because many Mathematica users won't have experience with advanced use of debuggers, such as this, and could really use a short walkthrough on how to do it with various debuggers/IDEs/compilers ... $\endgroup$
    – Szabolcs
    Jun 23, 2016 at 8:09

2 Answers 2


Yes, this is possible. In Mathematica print out $ProcessID then in GDB you can use attach to attach to that process id and you should be able to debug.


https://mathematica.stackexchange.com/a/118739/6804 discusses compiling a library link dll and attaching a debugger.

With say Visual Studio, you can just attach to process -> WolframKernel.exe after the dll has been loaded (via LibraryFunctionLoad).


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.