Using Boost Libraries with Mex function in MATLAB

23 ビュー (過去 30 日間)
Craig
Craig 2011 年 5 月 21 日
編集済み: John Kelly 2015 年 2 月 27 日
I am trying to write a Mex function and compile it in the MATLAB command window using
>> mex Cluster.cpp
I have already done mex -setup and written other Mex functions that run without error.
I am using the boost libraries for C++ in my program. This is one of the headers that I am using:
#include <boost/random/uniform_int.hpp>
It gives me the following error message when I try to compile:
fatal error C1083: Cannot open include file: 'boost/random /uniform_int.hpp': No such file or directory
I then included the full path name:
#include <C:/boost_1_46_1/boost/random/uniform_int.hpp>
and get a new error message:
C:\boost_1_46_1\boost\random\uniform_int.hpp(22) : fatal error C1083: Cannot open include file: 'boost/config.hpp': No such file or directory.
This indicates that it was able to open the header file that it previously couldn't. But inside the uniform_int.hpp file there is a #include boost/config.hpp and it can't open that header file.
I don't really feel like messing with the boost header files to try to get it to work. The boost libraries also work fine when I use them in Visual C++. Is there any way I can get this to work by doing something in the MATLAB editor or at the command window prompt? I know in Visual C++ I can just add additional "include" directories. Is there a similar way of doing this through MATLAB?

採用された回答

Kaustubha Govind
Kaustubha Govind 2011 年 5 月 23 日
You should just need to add additional include directories using the -I argument:
mex Cluster.cpp -IC:\boost_1_46_1

その他の回答 (3 件)

Ben Mitch
Ben Mitch 2011 年 5 月 22 日
Yup. Find your mexopts file (mexopts.bat, since you seem to be on Windows, which you'll find at something like c:\users\craig\appdata\roaming\mathworks\RXXXXx\mexopts.bat I think). At the top you'll find it defines the INCLUDE variable - just add the path to your boost files there, for example:
INCLUDE=C:\boost_1_46_1;C:\My\Other\Path;%MATLAB%\include;
  1 件のコメント
Ben Mitch
Ben Mitch 2011 年 5 月 22 日
PS. if you can't find, or can't work out how to edit, this file, an alternative is to set (or create) your user environment variable "INCLUDE" to include the path to boost, in a similar way. find this under my computer/properties/system or some such.

サインインしてコメントする。


Chirag Gupta
Chirag Gupta 2011 年 5 月 23 日
編集済み: John Kelly 2015 年 2 月 27 日
Another solution might be to create your mex files directly from Visual Studio:

Craig
Craig 2011 年 5 月 23 日
All the suggestions seem to work fine. I haven't tried running mex files from Visual Studio yet, but that will be my next step. Thanks to everyone for the suggestions.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by