1

It is in essence an C++ and compiler problem. But I will describe how does this error occur.

I am writing mathematica librarylink function using C++ and Eigen library, which is as follows

libsource = "#include \"WolframLibrary.h\"
  #include <Eigen/Dense>
  EXTERN_C DLLEXPORT int donothing(WolframLibraryData libData,mint \
Argc,MArgument*Args,MArgument Res) {
  using namespace std;
  using namespace Eigen;
  Matrix2d a;
  a<<1,2,3,4;
  return LIBRARY_NO_ERROR;}";

And load it as using

LibraryFunctionUnload[donothing];
libnew = CreateLibrary[libsource, "donothing", "Debug" -> True, 
   "CompileOptions" -> "-x c++"];
donothing = LibraryFunctionLoad[libnew, "donothing", {}, "Void"];

I turned on debug, and mathematica ouput shell compilation result as below:

C:\Users\qq\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\W\
indows-x86-64\Working-lenovo-qq-5144-7404-36>C:\mingw-w64\mingw64\bin\
\x86_64-w64-mingw32-gcc-5.2.0.exe -shared -o \
"C:\Users\qq\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\
\Windows-x86-64\Working-lenovo-qq-5144-7404-36\donothing.dll" -g -x c++ \
 -I"C:\Program Files\Wolfram \
Research\Mathematica\10.3\SystemFiles\IncludeFiles\C" -I"C:\Program \
Files\Wolfram \
Research\Mathematica\10.3\SystemFiles\Links\MathLink\DeveloperKit\W\
indows-x86-64\CompilerAdditions\mldev64\include" "C:\Users\qq\AppData\
\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\W\
orking-lenovo-qq-5144-7404-36\donothing.c"  -L"C:\Program \
Files\Wolfram \
Research\Mathematica\10.3\SystemFiles\Links\MathLink\DeveloperKit\W\
indows-x86-64\CompilerAdditions\mldev64\lib" -L"C:\Program \
Files\Wolfram \
Research\Mathematica\10.3\SystemFiles\Libraries\Windows-x86-64"    \
2>&1 
R:\temp\cc9bBS4s.o:donothing.c:(.data+0x0): undefined reference to \
`__gxx_personality_seh0'
R:\temp\cc9bBS4s.o:donothing.c:(.xdata+0x10): undefined reference to \
`__gxx_personality_seh0'
collect2.exe: error: ld returned 1 exit status

Yesterday, I run the same code, it works perfectly. While now, I don't know what is wrong.

At the same time, all librarylink without Eigen library works well. And Eigen library is not damaged, since I can compile .cpp file using Eigen without problem.

How to solve this?

update

I don't know why my question marked as duplicate without any comment! I read that link, and it didn't solve my problem! I already said "yesterday it works well". I already use option "-x c++", and I also tried "-x c++ -lstdc++" and the error is __gxx_personality_seh0 not ___gxx_personality_v0

user15964
  • 2,507
  • 2
  • 31
  • 57
  • That it worked "yesterday" does not mean that the error that causes this is caused between then and now. If you compile in steps, the compiler might have skipped a step before, because you didn't change a certain file. After you change that file, all the compilation steps have to be run. Have you done something compiler-related since the first time you compiled? – Sumurai8 Jan 13 '16 at 09:31
  • Or have you even tried to just delete all .o files and recompiling everything from scratch? – Sumurai8 Jan 13 '16 at 09:33
  • @Sumurai8 Thank you so much! You remind me to look into the history. Fortunately, mathematica's debug feature saved all the compilation shell message. And I found yesterday, the evoked compiler was `x86_64-w64-mingw32-g++.exe`, and today it is `x86_64-w64-mingw32-gcc-5.2.0.exe`. So now, I am clear, the link provided by Bo Persson really point out my problem. – user15964 Jan 13 '16 at 11:16

0 Answers0