3
$\begingroup$

Don't you just love it when your computer is working fine, you work with some good examples, everything is wonderful and your relationship with your computer is the best? I do. But what happens when your computer gets upgraded or maybe something changes along the way and then you come back to some old programs that you need? Two things can happen, either they work or they don't.

It has happened again. I'm not sure what I did in my macbook to mess up some path or to delete something that Mathematica needs but now my MathLink program isn't working.

Consider the solution I offered a while ago:

https://mathematica.stackexchange.com/a/5730/877

In this answer I explained step by step how to get the MathLink program to work. I have the source code and I repeatedly compiled it and it was working fine.

Today as I was writing a new MathLink program I started to get errors which I just couldn't figure out. So I went back to a program which I knew worked in the past and to my surprise, now that program doesn't work.

I had made a MakeFile for my mathlink program, here is the trash I get now when I run it:

dhcp09:mma jmlopez$ make
/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions/mprep mlprog.tm -o mlprogtm.cpp
g++ -c -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions mlprogtm.cpp
g++ -c -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions mlprog.cpp
g++ -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions mlprogtm.o mlprog.o ../fortran/myprog.o ../fortran/libminuit.a -L/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions -lMLi3 -lstdc++ -lgfortran -framework Foundation -o mlprog
Undefined symbols for architecture x86_64:
  "__Unwind_Resume", referenced from:
      _mlipinterfacecontainer_new in libMLi3.a(mlipinterface.c.o)
      _mlipinterfacecontainer_interfaces_changed in libMLi3.a(mlipinterface.c.o)
      _mlipinterfacecontainer_get_decimal_names in libMLi3.a(mlipinterface.c.o)
      _mlipinterfacecontainer_get_domain_names in libMLi3.a(mlipinterface.c.o)
      MLLists::MLList<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~MLList()in libMLi3.a(mlipinterface.c.o)
      MLLists::MLList<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~MLList()in libMLi3.a(mlipinterface.c.o)
      MLHashTables::MLHashTable<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, MLHashTables::MLGenericHashFunction<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~MLHashTable()in libMLi3.a(mlipinterface.c.o)
      ...
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [mlprog] Error 1

Oh, and this is not just for my programs, the example programs also don't work anymore. When I run make in

/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MathLinkExamples

I get the same errors:

/usr/bin/gcc -c  -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MathLinkExamples/../CompilerAdditions addtwotm.c
/usr/bin/gcc -c  -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MathLinkExamples/../CompilerAdditions addtwo.c
/usr/bin/c++  -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MathLinkExamples/../CompilerAdditions addtwotm.o addtwo.o -L/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MathLinkExamples/../CompilerAdditions -lMLi3 -lstdc++ -framework Foundation -o addtwo
Undefined symbols for architecture x86_64:
  "__Unwind_Resume", referenced from:
      _mlipinterfacecontainer_new in libMLi3.a(mlipinterface.c.o)
      _mlipinterfacecontainer_interfaces_changed in libMLi3.a(mlipinterface.c.o)
      _mlipinterfacecontainer_get_decimal_names in libMLi3.a(mlipinterface.c.o)
      _mlipinterfacecontainer_get_domain_names in libMLi3.a(mlipinterface.c.o)
      MLLists::MLList<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~MLList()in libMLi3.a(mlipinterface.c.o)
      MLLists::MLList<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~MLList()in libMLi3.a(mlipinterface.c.o)
      MLHashTables::MLHashTable<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, MLHashTables::MLGenericHashFunction<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~MLHashTable()in libMLi3.a(mlipinterface.c.o)
      ...
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [addtwo] Error 1

Have you experienced this? Did I do something to my computer to mess it up? How do I fix it so that I can get back to my actual work? I know this must be because it can't find some libraries but I don't know which libraries it now decided that it wants. This problem is under Mac OS X.

$\endgroup$
8
  • 1
    $\begingroup$ I will leave this question here but I will let you guys know that it can be closed down. Maybe not many people will experience this, but a quick fix is to switch compilers. I used g++-mp-4.5 from macports and that seems to work. I'm still clueless as to why the regular g++ is not working anymore. $\endgroup$
    – jmlopez
    Commented Jun 6, 2012 at 20:38
  • $\begingroup$ You can always delete it yourself if you think it's not relevant any more. $\endgroup$
    – Szabolcs
    Commented Jun 6, 2012 at 21:04
  • $\begingroup$ @Szabolcs, I'm not sure if its not relevant. I'm still interested to see how I can make it work with the regular g++ command as before. In any case, maybe someone will experience these type of errors in the future so I hope that it this question can become helpful at some point. $\endgroup$
    – jmlopez
    Commented Jun 6, 2012 at 21:10
  • $\begingroup$ Then you could add the extra information about the other compiler working to the question itself and update the question a bit. You can mention that you're on OS X and tag the question [maxosx]. $\endgroup$
    – Szabolcs
    Commented Jun 6, 2012 at 21:11
  • $\begingroup$ I'm having the same problem. I'm going to try installing another version of gcc like you suggest. If it works, you should consider answering your question and cleaning up your OP. $\endgroup$
    – CHM
    Commented Jun 26, 2012 at 20:28

1 Answer 1

1
$\begingroup$

In the comments I had mentioned a quick fix. Instead of using the regular g++ that comes when you install Xcode simply use another g++ version. In my case I used the one from macports, g++-mp-4.5. At the time when I did my edit explaining what to do to get it working I had showed the version of g++ that I had. This is the information on the g++ compilers installed when I had the problem:

dhcp09:~ jmlopez$ g++ -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/src/configure --disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
dhcp09:~ jmlopez$ g++-mp-4.5 -v
Using built-in specs.
COLLECT_GCC=g++-mp-4.5
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin11/4.5.3/lto-wrapper
Target: x86_64-apple-darwin11
Configured with: ../gcc-4.5.3/configure --prefix=/opt/local --build=x86_64-apple-darwin11 --enable-languages=c,c++,objc,obj-c++,fortran,java --libdir=/opt/local/lib/gcc45 --includedir=/opt/local/include/gcc45 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.5 --with-local-prefix=/opt/local --with-libiconv-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.5 --with-gxx-include-dir=/opt/local/include/gcc45/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --enable-stage1-checking --disable-multilib --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --enable-lto --enable-fully-dynamic-string --with-pkgversion='MacPorts gcc45 4.5.3_4'
Thread model: posix
gcc version 4.5.3 (MacPorts gcc45 4.5.3_4) 
dhcp09:~ jmlopez$ g++-mp-4.7 -v
Using built-in specs.
COLLECT_GCC=g++-mp-4.7
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin11/4.7.0/lto-wrapper
Target: x86_64-apple-darwin11
Configured with: ../gcc-4.7.0/configure --prefix=/opt/local --build=x86_64-apple-darwin11 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --enable-stage1-checking --disable-multilib --enable-lto --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc47 4.7.0_3'
Thread model: posix
gcc version 4.7.0 (MacPorts gcc47 4.7.0_3)

The only compiler that worked was g++-mp-4.5, the other two gave me the errors I showed in the question. Recently after CHM commented on the question I decided to upgrade my ports. That got me a little bit scared since g++-mp-4.5 was the only one working. In any case, I decided to make a simple hello world program using the regular g++ compiler and to my surprise I got the same errors as with the Mathematica Mathlink program. That hinted me to perform an upgrade. So I went to the app-store and I got a fresh copy of Xcode, installed it, went to the preferences and reinstalled the command line tools.

enter image description here

After that I went to the command line to check on the version of g++:

dhcp09:~ jmlopez$ g++ -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)

LLVM build 2336.9.00 > LLVM build 2335.15.00. Now my mac is working with the g++ provided by apple once again. I still have no idea why g++ would break at some point, but if that happens ever again, I will switch compilers and wait till there is an upgrade (this you have to check regularly on the Xcode preferences).

$\endgroup$

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.