2
votes

I am compiling a Matlab mex file (Using VS2010 under Windows), and the following 2 includes:

#include <algorithm> // for std::copy
#include "mex.h"

give me compile error:

1>d:\svn\trunk\dev\matlab\extern\include\matrix.h(337): error C2371: 'char16_t' : redefinition; different basic types

I have tried putting it in a namespace:

namespace Algo {    
    #include <algorithm>
}

But then I get tons of other compile errors, without even using anything defined in <algorithm>, for example:

Error   1   error C2039: 'set_terminate' : is not a member of '`global namespace''  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\exception    192
Error   2   error C2873: 'set_terminate' : symbol cannot be used in a using-declaration C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\exception    192

How can I solve this?

1
Have you tried the other way around, ie trying to put the mex header in a namespace? Read the header, and find the conflict. Often it is possible to define a symbol to circumvent it. - daramarak
It works, thanks. Put it into an answer and I will be glad to accept it.. btw, why it doesn't work the other way round? - Itamar Katz

1 Answers

1
votes

Putting an standard header in a namespace doesn't sound like a good idea, even though you are not using any of the methods or classes there, there is a pretty big chance that another header might (like the mex.h). Putting the namespace around the mex header seems much less probable to create a conflict.

Also including one header before the other might also prevent such a conflict. Some headers take into account that some symbol might already be defined before redefining them (library developer really should take care to do this)

In some cases reading the headers might also give you a good clue what is going on. Some times it might be as simple as defining a symbol, which tells the header to skip the redefinition.