1

I have downloaded and succesfully compiled metis 5.0.2 in a win7 x64 pc and trying to compile metismex. I compiled metis with Visual Studio 11 (2012) and using the same compiler from within matlab. After a lot of experimentation with a ton of errors (mainly owed to paths issues from within the libraries) I have reached a point where I dont know how to proceed, since my knowledge on c and c++ is pretty basic. So, here's the error :

../GKlib/mat_libs/.\stddef.h(16) : error C2054: expected '(' to follow '_SIZE_TYPE__' 
../GKlib/mat_libs/.\stddef.h(19) : error C2085: '_WCHAR_TYPE__' : not in formal parameter list 

I found out about the inline functions etc, but since the error is within a library and dont exactly know what I should be doing, here I am. So, the error code is produced here :

 typedef __SIZE_TYPE__ size_t; 
#ifndef __cplusplus
typedef __WCHAR_TYPE__ wchar_t; 
#endif

any suggestions on what I should do without messing it up? (in case I comment out wchar type, I also have the same error on prtdiff_type) Thanks in advance

P.S: In case it is needed, here's the whole sttdef.h

/* Copyright 2012 The MathWorks, Inc. */

#ifndef _STDDEF_H
#define _STDDEF_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
#  define NULL (0)
#else
#  define NULL ((void *)0)
#endif

typedef __SIZE_TYPE__ size_t; 

#ifndef __cplusplus
typedef __WCHAR_TYPE__ wchar_t; 
#endif

typedef __PTRDIFF_TYPE__ ptrdiff_t;

#if (! defined(__cplusplus)) || (! defined(PST_GNU))
# define offsetof(type, field) ((size_t) &((type *)0)->field)
#else
# define offsetof(type, field)                            \
  (__offsetof__(reinterpret_cast<size_t>                  \
        (&reinterpret_cast<const volatile char &> \
         (static_cast<type *>(0)->field))))
#endif

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* _STDDEF_H *

/

Amro
  • 123,847
  • 25
  • 243
  • 454
Es.T
  • 68
  • 6

1 Answers1

2

Here is a walk-through of what I did. I'm running R2014a with VS2013 on Win8.1 x64.

1) First we compile metis:

  • Download and extract metis-5.1.0 to some location, say C:\metis-5.1.0

  • Edit C:\metis-5.1.0\include\metis.h and set #define IDXTYPEWIDTH 64 (for x64 architecture)

  • Next we generate Visual Studio projects using CMake:

    > cd C:\metis-5.1.0
    > vsgen -G "Visual Studio 12 2013 Win64"
    
  • Before we build the solution, we need to fix a few things first. Some header files are unnecessarily redefining rint function for MSVC (metisbin.h, metislib.h, and gk_arch.h). Remove such lines:

    #ifdef __MSC__ /* MSC does not have rint() function */
    #define rint(x) ((int)((x)+0.5))  
    
    /* MSC does not have INFINITY defined */
    #ifndef INFINITY
    #define INFINITY FLT_MAX
    #endif
    #endif
    
  • Also in GKlib\gk_externs.h replace all occurrences of __thread with __declspec(thread)

  • Next open the solution file C:\metis-5.1.0\build\windows\METIS.sln in Visual Stduio, and build ALL_BUILD target (make sure "x64" in "Release" mode is selected).

  • We are mainly interested in the metis project. Its result should be stored in C:\metis-5.1.0\build\windows\libmetis\Release\metis.lib (a static library).

2) Next we build the MEX-function:

  • Download metismex and extract it to a folder inside the previous location (C:\metis-5.1.0\metismex-master)

  • Again we need to fix a few things: first rename metismex.c to metismex.cpp (the C++ compiler is much better than the C compiler in Visual Studio!). Next edit this file and replace: #include <strings.h> with #include <string.h>, and add the following code immediately after it:

    #if defined(_WIN32) || defined(_WIN64)
      #define snprintf _snprintf
      #define vsnprintf _vsnprintf
      #define strcasecmp _stricmp
      #define strncasecmp _strnicmp
    #endif
    
  • Finally start MATLAB, and run the following command to compile the MEX-file:

    >> cd('C:\metis-5.1.0\metismex-master')
    >> mex -O -largeArrayDims -DWIN32 -DMSC -DUSE_GKREGEX -I../GKlib -I../include -I../libmetis metismex.cpp ../build/windows/libmetis/Release/metis.lib
    
  • You should now have the final metismex.mexw64

I should say that I know nothing about the library, so I cannot guarantee it gives correct results after all the above modifications. I'm just showing how to get it to compile. The code was written with Linux/OSX in mind, and relies on many POSIX features not intended for Windows. Also the whole 32 vs. 64 bit is a bit messy...

Amro
  • 123,847
  • 25
  • 243
  • 454
  • 1
    Whoops !! My bad my bad!! Sorry, I should have told that I have downloaded a patched version of metis from here https://github.com/helixhorned/metis/tree/pk (it addressed the isues of gpmentis and ndmetis crashing on win7 machines and it worked for me). Here is the link to the forum that explains : http://glaros.dtc.umn.edu/gkhome/node/1095 – Es.T Sep 30 '14 at 09:04
  • OK problems solved, everything works as you said :D (The errors where owed to the fact that in cmake I hadnt chosen the x64 compiler.) (silly me..) A million thanks :D :D :D :D – Es.T Sep 30 '14 at 10:35
  • just so you should know, I am posting your solution to David Gleich's github page -with the appropriate reference of course :D – Es.T Oct 05 '14 at 08:16