Message Boards Message Boards

3 Replies
5 Total Likes
View groups...
Share this post:

MathLink on Mac OSX

Posted 10 years ago


I am trying to call a C program from within Mathematica. I have compiled the addtwo.c example provided by Wolfram Research with

fayard@Speed:MathLink$ /Applications/ --verbose addtwo.c
/Applications/ -o
/usr/bin/clang -I/Applications/ -arch i386 -arch x86_64  -c -o addtwo.o addtwo.c
/usr/bin/clang -I/Applications/ -arch i386 -arch x86_64  -c -o
/usr/bin/clang++ -I/Applications/ -arch i386 -arch x86_64  -o a.out addtwo.o  -L/Applications/ -lstdc++ -F /Applications/ -framework mathlink -framework Foundation

Unfortunately, when I try to load the library from Mathematica, I get a stall and I find that my application crashed. In ~/Library/Logs/DiagnosticReports, I get a crash from addtwo

Application Specific Information:
    dyld: launch, loading dependent libraries

Dyld Error Message:
    Library not loaded: @executable_path/../Frameworks/mathlink.framework/Versions/4.25/mathlink
    Referenced from: /Users/USER/Documents/*/addtwo
    Reason: image not found

Any help would be appreciated.

POSTED BY: Francois Fayard
3 Replies

The framework version of MathLink is intended to be used by .app bundles where it would be included in and would have the relative path you mention (@executable_path/../Frameworks/mathlink.framework).

If you're just building a command line tool (like the addtwo example) you'd be better off just linking against the static library (libMLi4.a).

Hi Rob,

I have tried to use mcc on OSX. Using:

mcc --verbose addtwo.c -o addtwo

gives the code above and does not work. If I try to link to a static library, I use

 mcc --verbose -st addtwo.c -o addtwo

and I have a lot of templates error.

POSTED BY: Francois Fayard

It looks like the most recent versions of clang now default to using the newer libc++. The MathLink static library was built against the older libstdc++ and in order for the executable to link correctly all the components need to agree on which standard library they're using. The fix is to add -stdlib=libstdc++ to the build command.

mcc --verbose -st addtwo.c -o addtwo -stdlib=libstdc++

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract