Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matlab uses a different version of boost compared to SIRF #207

Closed
rijobro opened this issue Nov 17, 2018 · 13 comments
Closed

Matlab uses a different version of boost compared to SIRF #207

rijobro opened this issue Nov 17, 2018 · 13 comments

Comments

@rijobro
Copy link
Contributor

rijobro commented Nov 17, 2018

I'm trying to get SIRF installed on the remote desktop to the university. This means that we don't have complete control over installed packages etc.

I installed SIRF using a version of boost that we installed ourselves (/slms/inm/research/tools/TL/lib/libboost_[component].so.1.68.0). However, Matlab is using its own version of boost (/cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libboost_[component].so.1.56.0). This causes matlab to crash as I try to load the SIRF libraries and the ctests fail accordingly.

I gave the following a go: cmake --DCMAKE_MODULE_LINKER_FLAGS=-Wl,--exclude-libs,ALL, which I got from here, but no luck.

Anyone got any expierence or ideas?

@rijobro rijobro changed the title library versions and boost Matlab uses a different version of boost compared to SIRF Nov 17, 2018
@ashgillman
Copy link
Member

Can you use the Boost that MATLAB uses for SIRF, or is the version inappropriate?

@KrisThielemans
Copy link
Member

MATLAB renamed the shared libs to libmwboost_program_options.so.* (presumably to avoid conflicts) so setting BOOST_ROOT won’t work.

example error:

6: Abnormal termination:
6: Segmentation violation
6: 
6: Register State (from fault):
6:   RAX = 00007f3d2aa54c20  RBX = 00007f3d2aa54c20
6:   RCX = 00007f3cc43a7440  RDX = 00007f3d24000078
6:   RSP = 00007f3d2aa54b20  RBP = 00007f3d24000078
6:   RSI = 0000000000000000  RDI = 0000000000000001
6: 
6:    R8 = 0000000000000001   R9 = 4c54414d2f73746e
6:   R10 = 4f2d6464412f4241  R11 = 6c6f6f742e2f736e
6:   R12 = 0000000000000000  R13 = 00007f3d2aa54dbc
6:   R14 = 00007f3cc495e428  R15 = 00007f3d2aa54dc0
6: 
6:   RIP = 00007f3d5260549d  EFL = 0000000000010202
6: 
6:    CS = 0033   FS = 0000   GS = 0000
6: 
6: Stack Trace (from fault):
6: [  0] 0x00007f3d5260549d /slms/inm/research/tools/TL/lib/libboost_filesystem.so.1.68.0+00042141 _ZN5boost10filesystem6detail14symlink_statusERKNS0_4pathEPNS_6system10error_codeE+00000029
6: [  1] 0x00007f3d33629b17 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwPathNameResolver.so+00047895 _ZN16PathNameResolver11bnIsSymlinkERKSbIDsSt11char_traitsIDsESaIDsEE+00000055
6: [  2] 0x00007f3d33629c7a /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwPathNameResolver.so+00048250 _Z7bnIsDirRKSbIDsSt11char_traitsIDsESaIDsEE+00000026
6: [  3] 0x00007f3d3362b8df /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwPathNameResolver.so+00055519 _ZN16PathNameResolver38openFileThroughFullPathOrCWDThenMLPathERSbIDsSt11char_traitsIDsESaIDsEERKSsS4_Ri+00000255
6: [  4] 0x00007f3d3385e6a9 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwfileio.so+00173737
6: [  5] 0x00007f3d338591f0 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwfileio.so+00152048
6: [  6] 0x00007f3d3386d999 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwfileio.so+00235929
6: [  7] 0x00007f3d3ad61cfe /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_dispatcher.so+00437502
6: [  8] 0x00007f3d3ad48878 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_dispatcher.so+00333944 _ZN13Mfh_MATLAB_fn11dispatch_fhEiPP11mxArray_tagiS2_+00000616
6: [  9] 0x00007f3d37bed847 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+11675719
6: [ 10] 0x00007f3d37bedaab /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+11676331
6: [ 11] 0x00007f3d37c53411 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+12092433
6: [ 12] 0x00007f3d37579930 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+04909360
6: [ 13] 0x00007f3d3757bc3c /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+04918332
6: [ 14] 0x00007f3d37578410 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+04903952
6: [ 15] 0x00007f3d37573855 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+04884565
6: [ 16] 0x00007f3d37573b69 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+04885353
6: [ 17] 0x00007f3d3757820d /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+04903437
6: [ 18] 0x00007f3d375782e2 /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwm_lxe.so+04903650
...

@KrisThielemans
Copy link
Member

we're not 100% sure which CMake flag to use to pass this to the linker.

@KrisThielemans
Copy link
Member

KrisThielemans commented Nov 18, 2018

Linking mstir.mex with the above doesn't help. I then get

loadlibrary('msirfreg')
/slms/inm/research/tools/TL/matlab/msirfreg.mexa64: undefined symbol:
_ZN5boost6system6detail20generic_category_ncxEv

Using

LD_PRELOAD=/lib64/libgomp.so.1\:/slms/inm/research/tools/TL/lib/libboost_filesystem.so.1.68.0\:/slms/inm/research/tools/TL/lib/libboost_system.so.1.68.0

causes Matlab to crash immediatelly (as it has 1.56.0 internally)

@KrisThielemans
Copy link
Member

My current feeling is that it'd be best to build with the same boost version as matlab, even if we don't use the matlab boost distributed libraries (because of the renaming of the libraries, I'm not sure if we can do that anyway).

That in itself isn't trivial. We can set BOOST_ROOT when building SIRF, but whatever it finds is currently overwritten by boost-dependencies in its dependencies. In particular, STIRConfig.cmake.in attempts to make sure that if you're using STIR, you'll be using the same boost/ITK etc version as what it was compiled with (which seems sensible enough). It will therefore set BOOST_ROOT and BOOST_INCLUDEDIR.

Enforcing some kind of consistency seems only doable by using the Superbuild.

@KrisThielemans
Copy link
Member

The alternative might be to statically link with boost. Presumably -DBoost_USE_STATIC_LIBS might do that.

@KrisThielemans
Copy link
Member

@KrisThielemans
Copy link
Member

I managed to compile with statically linked boost libraries. This wasn't trivial, but it didn't help. Crash is still


Thread 32 (Thread 0x7f974d39d700 (LWP 9484)):
#0  0x00007f976cc05995 in pthread_cond_wait

GLIBC_2.3.2 () at /lib64/libpthread.so.0
#1  0x00007f976e8a89fb in boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) () at /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwmvm.so
#2  0x00007f976e8aaafb in boost::detail::shared_state_base::wait_internal(boost::unique_lock<boost::mutex>&, bool) () at /cs/sys/software2/Matlab/matlab-R2016b/bin/glnxa64/libmwmvm.so
...

I'll document the steps I had to follow:

  1. build boost appropriately (i.e. static libs, but with -fPIC)
SRCDIR=../../../src/boost_1_68_0
mkdir -p boost/1_68_0
cd boost/1_68_0
BUILDPATH=`pwd`
$SRCDIR/bootstrap.sh --prefix=$INSTALLDIR
cd $SRCDIR
$BUILDPATH/b2 --build-dir=$BUILDPATH \
  --prefix=${where}/TL/boost_1_68_0_static_versioned \
  --layout=versioned link=static  -cxxflags=-fPIC install

Notes:

  • you need -fPIC on Linux. Otherwise we cannot use this library to link a mex library with. This means that likely no "system-provided" static boost libraries would work.
  1. Build SIRF with that Boost version
whereboost=${where}/TL/boost_1_68_0_static_versioned
cmake . -UBoost_INCLUDE_DIR -DBoost_NO_SYSTEM_PATHS=ON \
 -DBOOST_ROOT=${whereboost} \
 -DBOOST_INCLUDEDIR=${whereboost}/include/  -DBOOST_LIBRARYDIR=${whereboost}/lib \
 -DBoost_USE_STATIC_LIBS=ON \
 -DBoost_ARCHITECTURE=-x64 -DCMAKE_CXX_COMPILER_ARCHITECTURE_ID=x64  

make install

Notes:

  • specifying BOOST_INCLUDEDIR and BOOST_LIBRARYDIR was probably not necessary
  • I had to set CMAKE_CXX_COMPILER_ARCHITECTURE_ID as there's a bug in CMake that's being fixed that it doesn't find the boost libraries if you installed them with versioned. I probably could have avoided this by using tagged instead.

@KrisThielemans
Copy link
Member

Crash is here but is simply due to anything calling filename.string() where filename is a boost::filesystem::path

@KrisThielemans
Copy link
Member

KrisThielemans commented Nov 18, 2018

Hallelujah! I finally managed to get this to work by

  • recompiling STIR with boost 1.56.0
  • making sure that SIRF uses the appropriate STIR and boost version.

@rijobro, I believe you edited CMakeLists.txt in our CentOS system to put in a requirement for boost which was more recent than 1.56.0, although the original (on git) is just 1.36.0. Any idea why you did that?

Notes:

@KrisThielemans KrisThielemans transferred this issue from SyneRBI/SIRF Feb 23, 2019
@KrisThielemans
Copy link
Member

* Gadgetron currently requires 1.64.0. I've asked them about Matlab issues

They experience the same troubles.

@KrisThielemans
Copy link
Member

Info from MathWorks:

The BOOST libraries that MATLAB internally uses are as follows:
MATLAB R2016a - R2017b Boost library version 1.56.
MATLAB R2014a to R2015b Boost library version is 1.49
From MATLAB R2018a, our development team has eliminated the compatibility restrictions for the Boost C++ Library.

@KrisThielemans
Copy link
Member

closing as only applies to old MATLAB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants