c++ engine API: minimal example gives segmentation fault, see stacktrace

7 Ansichten (letzte 30 Tage)
SA-W
SA-W am 23 Jun. 2023
Beantwortet: Varun am 25 Aug. 2023
I built an c++ API engine using a minimal example as shown here
My exexutable is however linked against a whole bunch of other libraries and I think there is an issue with ABI incompatible versions of the same external library linked into the executable.
The issue is that the call to startMATLAB() results in a segmentation fault. To debug this, I produced the following stacktrace with gdb:
As you can see, at the top of the stacktrace is the libmwmvm.so library.
What is this library used for and do you have any idea what triggers the segfault?
Starting program: /step-1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffbddff640 (LWP 3220190)]
[New Thread 0x7fffbd5fe640 (LWP 3220191)]
Thread 3 "step-1" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffbd5fe640 (LWP 3220191)]
0x00007fffc60cab83 in ?? () from /opt/MATLAB/R2023a/bin/glnxa64/libmwmvm.so
(gdb) bt
#0 0x00007fffc60cab83 in ?? () from /opt/MATLAB/R2023a/bin/glnxa64/libmwmvm.so
#1 0x00007fffd7099f68 in __pthread_once_slow (once_control=0x5555558569a0, init_routine=0x7fffd74dadb0 <__once_proxy>) at ./nptl/pthread_once.c:116
#2 0x00007fffc60ca6cd in mvm::detail::DefaultSession::getTransportSession() const () from /opt/MATLAB/R2023a/bin/glnxa64/libmwmvm.so
#3 0x00007fffc60bc8e1 in ?? () from /opt/MATLAB/R2023a/bin/glnxa64/libmwmvm.so
#4 0x00007fffc60f9cbd in ?? () from /opt/MATLAB/R2023a/bin/glnxa64/libmwmvm.so
#5 0x00007fffc60fa152 in mvm::MatlabFactory::createFactory(mwboost::shared_ptr<mvm::Session> const&, mvm::FactoryOptions const&, mvm::ShutdownPolicy, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, fl::filesystem::basic_path<char, char16_t, fl::filesystem::detail::path_traits<char, char16_t> >, std::shared_ptr<mvm::Credentials>, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, bool, unsigned long, std::optional<mwboost::chrono::duration<long, mwboost::ratio<1l, 1l> > >, bool) ()
from /opt/MATLAB/R2023a/bin/glnxa64/libmwmvm.so
#6 0x00007fffc6408a54 in ?? () from /opt/MATLAB/R2023a/bin/glnxa64/libmwengine_api.so
#7 0x00007fffc641ac1c in std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> (), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<unsigned long long>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<unsigned long long (*)(std::vector<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >, std::allocator<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> > > >), std::vector<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >, std::allocator<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> > > > > >, unsigned long long> >::_M_invoke(std::_Any_data const&) () from /opt/MATLAB/R2023a/bin/glnxa64/libmwengine_api.so
#8 0x00005555555f781a in std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>::operator()() const (this=0x7fffbd5ef780) at /usr/include/c++/12/bits/std_function.h:591
#9 0x00005555555efb8e in std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*) (this=0x7fffb8000b80, __f=0x7fffbd5ef780,
__did_set=0x7fffbd5ef757) at /usr/include/c++/12/future:572
#10 0x00007fffd7099f68 in __pthread_once_slow (once_control=0x7fffb8000b98, init_routine=0x7fffd74dadb0 <__once_proxy>) at ./nptl/pthread_once.c:116
#11 0x00007fffc641d3fc in std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<unsigned long long (*)(std::vector<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >, std::allocator<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> > > >), std::vector<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >, std::allocator<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> > > > > >, unsigned long long>::_Async_state_impl(std::thread::_Invoker<std::tuple<unsigned long long (*)(std::vector<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >, std::allocator<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> > > >), std::vector<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >, std::allocator<std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> > > > > >&&)::{lambda()#1}> > >::_M_run() ()
from /opt/MATLAB/R2023a/bin/glnxa64/libmwengine_api.so
#12 0x00007fffd74dc2b3 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#13 0x00007fffd7094b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#14 0x00007fffd7126a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  1 Kommentar
SA-W
SA-W am 28 Jun. 2023
@James Tursa Is this maybe a question you can help? You already answered one of my questions regarding a mex routine.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Varun
Varun am 25 Aug. 2023
Hi,
I understand you are using C++ Engine API using example shown in https://de.mathworks.com/help/matlab/matlab_external/test-your-build-environment.html but you are facing segmentation fault in startMATLAB().You are also linking other external libraries with this code.
I have compiled and build this code on R2023a with MATLAB Support for MinGW-w64 C/C++ Compilerby using following commands and it executed without any errors:
mex -setup -client engine C++
mex -client engine testFeval.cpp
I think issue might be with external libraries that you are linking along with this code. You can include and link external libraries with following flags:
-I<pathname>
Add <pathname> to the list of directories to search for #include
files. Do not add a space after this switch.
-l<name>
Link with object library. On Windows, <name> expands to
"<name>.lib" or "lib<name>.lib". On Linux, to "lib<name>.so".
On Mac, to "lib<name>.dylib". Do not add a space after this
switch.
-L<folder>
Add <folder> to the list of folders to search for
libraries specified with the -l option. Do not add a space
after this switch.

Kategorien

Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by