I'm trying to generate a MathLink executable by CCompilerDriver package. The MathLink executable produced by Makefile works properly. However, when I'm trying to generate the same thing by CCompilerDriver, an executable can be generated and installed without any warnings. But it keeps crashing whenever I tried to use its functions. And the link closed automatically.

Any ideas on how to fix this issue?

Files cddmathlink.c, cddmathlink.tm, cddmlio.c, cddmlio.h, mathlink.h and the original Makefile can be found in
https://github.com/mcmtroffaes/cddlib/tree/master/src-mathlink2 .

One may also find the latest source file for cddlib through the link above.

I'm using OS X and I installed cddlib and GMP libraries via Homebrew. So I changed the Makefile according to my system and the installation of Mathematica, cddlib and GMP. The Makefile works and the resulting executable works properly too. But I don't know how to produce the executable via CCompilerDriver package.

The Makefile

MLINKDIR = /Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit
SYS = MacOSX-x86-64
CADDSDIR = ${MLINKDIR}/${SYS}/CompilerAdditions
RM = rm
EXTRA_LIBS = -stdlib=libstdc++ -lstdc++ -framework Foundation
CC = /usr/bin/clang

BINARIES = cddmlgmp

all : $(BINARIES)

cddmlgmp : cddmathlinktm.o cddmathlink.o cddmlio.o
    ${CC} -I${INCDIR} cddmlio.o cddmathlinktm.o cddmathlink.o -L${LIBDIR} ${MATHLINK_LIB} ${EXTRA_LIBS} -lgmp /usr/local/lib/libcddgmp.a -o cddmlgmp

cddmathlinktm.o: cddmathlinktm.c
    $(CC) -c cddmathlinktm.c

cddmathlink.o: cddmathlink.c
    $(CC) -c cddmathlink.c -o cddmathlink.o

cddmlio.o: cddmlio.c
    $(CC) -DGMPRATIONAL -c cddmlio.c -o cddmlio.o

cddmathlinktm.c : cddmathlink.tm
    ${MPREP} $? > $@

    ${RM} -rf *.o *tm.c $(BINARIES)

First attempt (not working):

dir = FileNameJoin[{"~/", "OneDrive", "Documents", "Bitbucket", "cddlib", "src-mathlink"}];
src = FileNames[{"cddmathlink.*", "cddmlio.c"}, dir, Infinity];
CreateExecutable[src, "cddmlgmp", "Libraries" -> {"/usr/local/lib/libgmp.a", "/usr/local/lib/libcddgmp.a"}, "Defines" -> "GMPRATIONAL", "ShellOutputFunction" :> Print, "ShellCommandFunction" :> Print, "TargetDirectory" -> dir]

Another attempt (not working either):

dir = FileNameJoin[{"~/", "OneDrive", "Documents", "Bitbucket", "cddlib", "src-mathlink"}];
src = FileNames["cddmathlink.*", dir, Infinity];
srcext = FileNames["cddmlio.c",dir,Infinity];
obj = CreateObjectFile[srcext, "cddmlio", "Defines" -> "GMPRATIONAL", "ShellOutputFunction" :> Print, "ShellCommandFunction" :> Print, "TargetDirectory" -> dir];
CreateExecutable[src, "cddmlgmp", "Libraries" -> {"/usr/local/lib/libcddgmp.a", "/usr/local/lib/libgmp.a"}, "ExtraObjectFiles" -> obj, "ShellOutputFunction" :> Print, "ShellCommandFunction" :> Print, "TargetDirectory" -> dir]
  • $\begingroup$ Please post the code or a substitute that demonstrates the problem. Otherwise, it is very hard to say what might be going on here. $\endgroup$ Apr 27, 2015 at 13:38
  • $\begingroup$ @Oleksandr R.: May I ask what else are needed? Are those *.c, *.tm and *io.c files useful here? Or you mean the compilation output? $\endgroup$
    – hxiao
    Apr 27, 2015 at 14:34
  • $\begingroup$ Well, without the ability to generate or examine the executable, it is really not possible to guess what is wrong with it based on your description. It sounds like the executable is crashing, but who knows what the reason for that may be given what you say here. I personally cannot help you anyway as I don't have a Mac, but the question should contain sufficient information for someone else to be able to reproduce the problem. Otherwise you are depending on someone else having encountered this specific problem before in their own work to know how to answer you. $\endgroup$ Apr 27, 2015 at 17:42
  • $\begingroup$ @OleksandrR.: Thank you so much for your suggestions. I will edit my question to make it reproducible for someone who is interested. $\endgroup$
    – hxiao
    Apr 28, 2015 at 4:04


Your Answer

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

Browse other questions tagged or ask your own question.