Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:51:09+00:00 2026-06-07T23:51:09+00:00

I have a C++ library with a particular function that returns a boost::any ,

  • 0

I have a C++ library with a particular function that returns a boost::any, whose value type is a particular enum defined in a different included library. This normally works fine.

But when I link to my library dynamically from a Matlab mex file, typeid(the_enum_t) seems to be different for the things made in my library and those made in the caller, in that it doesn’t compare ==. Since I’m actually using flann, whose version of boost::any performs a check based on type_info::==, this makes everything break. Static linking works fine, but that’s kind of a pain here, and I’d really rather have it work either way.

I thought type_info::== was supposed to work consistently across library boundaries. Does this have to do with how Matlab dynamically loads libraries from mex?


Here’s some code to reproduce this (also available in easy-to-download form, with a makefile, in this gist).

First, a stand-in for the library that defines the enum (flann):

namespace library {
    enum the_enum_t { el_one, el_two, el_three };
}

Now a proxy for my library, stubby.hpp:

#include <boost/any.hpp>
#include "the_enum.hpp"
boost::any the_function();

And its implementation stubby.cpp:

#include "stubby.hpp"
boost::any the_function() {
    return boost::any(library::el_two);
}

Finally, test code test.cpp, which is compiled with -DNO_MEX for a standalone and not for a mex file:

#include "stubby.hpp"
#include <boost/any.hpp>

#ifdef NO_MEX
#include <cstdio>
using std::printf;
int main() {
#else
#include "mex.h"
void mexFunction(int nlhs, mxArray **plhs, int nrhs, const mxArray **prsh) {
#endif
    boost::any val_any = the_function();
    printf("%s (equal: %d)\n",
            val_any.type().name(),
            val_any.type() == typeid(library::the_enum_t));
}

I get the expected output

N5flann17flann_algorithm_tE (equal: 1)

from each of

$ g++ -o test{,.cpp} -DNO_MEX libstubby.a && ./test      
$ g++ -o test{_s,.cpp} -DNO_MEX libstubby.so && ./test_s
$ ln -sf test{,_s}.cpp && mex test_s.cpp libstubby.a && matlab -r test

But dynamically linking a mex file doesn’t work:

$ mex test.cpp libstubby.so && matlab -r test
N5flann17flann_algorithm_tE (equal: 0)

I see this same behavior on

  • Matlab R2011b and R2011a, OSX 10.7, Apple gcc 4.2.1
  • Matlab R2011b, CentOS 5.7, gcc 4.1.2
  • Matlab R2010a, Ubuntu 11.04, gcc 4.4.5

The weird thing is that I could’ve sworn it worked a few months ago, but maybe I just did a bad job of testing.

Obviously I can get around this by static linking. But why is this happening? Does it have something to do with the way Matlab loads mex files and their libraries?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:51:10+00:00Added an answer on June 7, 2026 at 11:51 pm

    Boost has a workaround for this issue; see https://svn.boost.org/trac/boost/ticket/754

    It’s possible that boost is failing to enable the workaround. Try passing compiler flag -DBOOST_AUX_ANY_TYPE_ID_NAME per the patch on that ticket.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to set a function pointer in a library API, such that it
Does Haskell standard library have a function that given a list and a predicate,
I have a problem; I'm using an external library where one particular event has
I have to implement a IExceptionHandler for the Enteprise Library 4.1. In my particular
I have a library made in C++/GDI that I am trying to port to
I have a library project that should be the base for several web applications.
I have a library that interacts with our phone system, ie, Hey phone, call
I have a library written in C that I would like to use in
Is there an R library/function that would implement INTELLIGENT label placement in R plot?
I have a third party library that I'm attempting to incorporate into a simulation.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.