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
INCDIR = ${CADDSDIR}
LIBDIR = ${CADDSDIR}
MPREP = ${CADDSDIR}/mprep
RM = rm
EXTRA_LIBS = -stdlib=libstdc++ -lstdc++ -framework Foundation
MATHLINK_LIB = -lMLi4
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} $? > $@
clean:
${RM} -rf *.o *tm.c $(BINARIES)
First attempt (not working):
Needs["CCompilerDriver`"];
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):
Needs["CCompilerDriver`"];
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]
Comments
Post a Comment