Commits

Anonymous committed dd9a65b

MinGW and MATLAB compatible

Comments (0)

Files changed (7)

include/dll_stuff.h

 #ifndef  _DLL_STUFF_HPP_
 #define  _DLL_STUFF_HPP_
 
+/* use stdcall convention under Windows, since this seems to
+   be more standard there and is important for calling from .NET */
+#if defined(_WIN32) || defined(__WIN32__)
+#  if defined(__GNUC__)
+#    define BAYESOPT_STDCALL __attribute__((stdcall))
+#  elif defined(_MSC_VER) || defined(_ICC) || defined(_STDCALL_SUPPORTED)
+#    define BAYESOPT_STDCALL __stdcall
+#  else
+#    define BAYESOPT_STDCALL
+#  endif
+#else
+#  define BAYESOPT_STDCALL
+#endif
+
 /* WINDOWS DLLs stuff */
-#if defined (_WIN32) && defined (BAYESOPT_DLL)
+#if defined (BAYESOPT_DLL) && (defined(_WIN32) || defined(__WIN32__)) && !defined(__LCC__)
   #if defined(bayesopt_EXPORTS)
     #define  BAYESOPT_API __declspec(dllexport)
+	#define  BAYESOPT_C_API(T) extern __declspec(dllexport) T BAYESOPT_STDCALL
   #else
     #define  BAYESOPT_API __declspec(dllimport)
+	#define  BAYESOPT_C_API(T) extern __declspec(dllimport) T BAYESOPT_STDCALL
   #endif /* MyLibrary_EXPORTS */
 #else /* defined (_WIN32) */
  #define BAYESOPT_API
+ #define BAYESOPT_C_API(T) extern T BAYESOPT_STDCALL
 #endif
 
         

include/parameters.h

   /* These functions are added to simplify wrapping code       */
   /*************************************************************/
   /* surrogate_name str2surrogate (const char* name); */
-  learning_type  str2learn     (const char* name);
+  BAYESOPT_C_API(learning_type)  str2learn     (const char* name);
 
   /* BAYESOPT_API const char* surrogate2str(surrogate_name name); */
-  BAYESOPT_API const char* learn2str(learning_type name);
+  BAYESOPT_C_API(const char*) learn2str(learning_type name);
 
-  BAYESOPT_API bopt_params initialize_parameters_to_default(void);
+  BAYESOPT_C_API(bopt_params) initialize_parameters_to_default(void);
 
 #ifdef __cplusplus
 }
+MATLABROOT=C:\Program Files (x86)\MATLAB\R2010a
+CC=mingw32-c++
+INCLUDES=-I"$(MATLABROOT)\extern\include" -I"." -I"..\include" -I"..\wrappers"
+LIBS=-L"$(MATLABROOT)\bin\win32" -lmex -lmx -leng -lmat
+FLAGS=-shared -DMATLAB_MEX_FILE -Wl,--export-all-symbols
+
+all: disc cont
+
+cont:
+	$(CC) $(FLAGS) $(INCLUDES) -o bayesopt.mexw32  bayesoptmex.c libbayesopt.dll $(LIBS)
+
+disc:
+	$(CC) $(FLAGS) $(INCLUDES) -o bayesoptdisc.mexw32  bayesoptdiscmex.c libbayesopt.dll $(LIBS)
+
+#mingw32-c++ -shared -I"C:\Program Files (x86)\MATLAB\R2010a\extern\include" -I"." -I"..\include" -I"..\wrappers" -DMATLAB_MEX_FILE -o bayesoptdisc.mexw32 -Wl,--export-all-symbols bayesoptdiscmex.c libbayesopt.dll -L"C:\Program Files (x86)\MATLAB\R2010a\bin\win32" -lmex -lmx -leng -lmat
+
+
+
+
+
+
+
+
+

matlab/bayesoptextras.h

 #include <math.h>
 #include <mex.h>
 
+#include "bayesoptwpr.h"
 #include "parameters.h"
-#include "bayesoptwpr.h"
+
 
 #define CHECK0(cond, msg) if (!(cond)) mexErrMsgTxt(msg);
 
 static void struct_string(const mxArray *s, const char *name, char* result)
 {
   mxArray *val = mxGetField(s, 0, name);
-  char *valstr;
 
   if (val) {
     if( mxIsChar(val) ) {
   
   /* See parameters.h for the available options */
   
-  char log_str[100], k_s_str[100];
   char l_str[100];
   size_t n_hp_test, n_coef_test;
 

matlab/bayesoptmex.c

     {
       params = mxCreateStructMatrix(1,1,0,NULL);
     }
-
   parameters = load_parameters(params);
 
   if(nrhs == 5)
     }
   else
     {
-      lb = mxCalloc(nDim,sizeof(double));
-      ub = mxCalloc(nDim,sizeof(double));
+      lb = (double*)(mxCalloc(nDim,sizeof(double)));
+      ub = (double*)(mxCalloc(nDim,sizeof(double)));
 	 
 
       
 
 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
 
-#define NOMINMAX
+#ifndef NOMINMAX
+#  define NOMINMAX
+#endif
 #include <windows.h>
 
 inline std::string NowTime()

wrappers/bayesoptwpr.h

  * 
  * @return error code
  */
-  BAYESOPT_API int bayes_optimization(int nDim, eval_func f, void* f_data,
+  BAYESOPT_C_API(int) bayes_optimization(int nDim, eval_func f, void* f_data,
 			 const double *lb, const double *ub,
 			 double *x, double *minf,
 			 bopt_params parameters);
  * 
  * @return error code
  */
-  BAYESOPT_API int bayes_optimization_disc(int nDim, eval_func f, void* f_data,
+  BAYESOPT_C_API(int) bayes_optimization_disc(int nDim, eval_func f, void* f_data,
 			      double *valid_x, size_t n_points,
 			      double *x, double *minf,
 			      bopt_params parameters);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.