Message Boards Message Boards

0
|
13542 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

MathLink on Mac OSX

Posted 10 years ago

Hello,

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/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions/mcc --verbose addtwo.tm addtwo.c
/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions/mprep   addtwo.tm -o a.out.tm.c
/usr/bin/clang -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions -arch i386 -arch x86_64  -c -o addtwo.o addtwo.c
/usr/bin/clang -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions -arch i386 -arch x86_64  -c -o a.out.tm.o a.out.tm.c
/usr/bin/clang++ -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions -arch i386 -arch x86_64  -o a.out addtwo.o a.out.tm.o  -L/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions -lstdc++ -F /Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions -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 YourApp.app/Contents/Frameworks/mathlink.framework 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.tm 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.tm 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.tm addtwo.c -o addtwo -stdlib=libstdc++

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

Group Abstract Group Abstract