1

I have encounter EXEC_BAD_ACCESS error in my local environment (Mac OS X 10.9.2, boost 1.55.0, mlpack 1.0.8, llvm 5.1 clang-503.0.38), and I have narrowed down the error in a very simple snippet:

#include "mlpack/methods/range_search/range_search.hpp"

int main(int argc, const char *argv[])
{
    return 0;
}

The g++ version is

iMac:build dongli$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

and compile the snippet by

g++ -std=c++11 main.cpp -o main -lmlpack -I/usr/include/libxml2

(you may change to your case)

Run main in terminal will give you

iMac:build dongli$ ./main
Bus error: 10

and run it in lldb will give you more information

iMac:build dongli$ lldb ./main
Current executable set to './main' (x86_64).
(lldb) r
Process 79449 launched: './main' (x86_64)
Process 79449 stopped
* thread #1: tid = 0xb4a75, 0x00000001000500eb libmlpack.1.0.dylib`long double boost::math::lanczos::lanczos17m64::lanczos_sum<long double>(long double const&) + 59, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x100001d80)
    frame #0: 0x00000001000500eb libmlpack.1.0.dylib`long double boost::math::lanczos::lanczos17m64::lanczos_sum<long double>(long double const&) + 59
libmlpack.1.0.dylib`long double boost::math::lanczos::lanczos17m64::lanczos_sum<long double>(long double const&) + 59:
-> 0x1000500eb:  fstpt  (%rax)
   0x1000500ed:  fldt   0x26c8d(%rip)             ; .memset_pattern99 + 1296
   0x1000500f3:  fstpt  0x10(%rax)
   0x1000500f6:  fldt   0x26c94(%rip)             ; .memset_pattern99 + 1312

As you can see, it point me to boost::math::lanczos::lanczos17m64::lanczos_sum, but I have no idea what is the problem.

But when -std=c++11 is absent, no error occurs. I also tried to reinstall boost with --c++11 by homebrew.

Thanks in advance!

EDIT:

I have only installed one boost:

iMac:~ dongli$ ls /usr/local/Cellar/boost/
1.55.0

with command:

brew install boost --c++11
coatless
  • 20,011
  • 13
  • 69
  • 84
Li Dong
  • 1,088
  • 2
  • 16
  • 27

2 Answers2

1

You could check that the actual shared library file is marked executable and is accessible to the user that runs the application?

It that isn't it, this probably means that at runtime you find a conflicting version of the library. Fix/override the runtime library path, or compile against the same version of the library if so

sehe
  • 374,641
  • 47
  • 450
  • 633
  • I can assure that there is no conflicting version of the library, since I only installed `boost` and `mlpack` from `homebrew`. – Li Dong Mar 20 '14 at 09:29
  • Then my money is squarely on the permissions – sehe Mar 20 '14 at 09:32
  • But the error is gone when no `-std=c++11` option is present. – Li Dong Mar 20 '14 at 09:40
  • Then you **do** have a conflicting version of Boost installed. Apparently the homebrew version **wasn't** compiled with --std=c++11. This will result in code violating the **[ODR](http://en.wikipedia.org/wiki/One_Definition_Rule)**. See e.g. http://stackoverflow.com/questions/4192170/what-exactly-is-one-definition-rule-in-c – sehe Mar 20 '14 at 09:43
  • @LiDong by the way, that information is missing from the question. – sehe Mar 20 '14 at 09:43
  • Sorry, I forget to mention it! – Li Dong Mar 20 '14 at 09:48
0

After I removed all the C++11 features from my codes (e.g., initializer_list and default template argument), and removed the -std=c++11 option, the error is gone. I think I have installed boost, mlpack with -std=c++11 by using homebrew, but the error persisted, so my experience is not use the new features if they are not necessary.

Li Dong
  • 1,088
  • 2
  • 16
  • 27