0

I am trying to write a very simple test application that uses Matlab C++ interface. My machine is running CentOs7 that comes with the default gcc 4.8.5. But for my application, I need gcc 7+, so I have installed gcc 7.3.1 as well. For compiling this mini-app, I use this command:

g++ -o matlab_test matlab_test.cpp   -I/home/matlab/lnx_x64/R2017B/release/inc -L/home/matlab/R2017B/release/lib -lMatlabEngine -lpthread -Wl,-v

but I am facing this issue:

collect2 version 7.3.1 20180303 (Red Hat 7.3.1-5)
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld -plugin /opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/liblto_plugin.so -plugin-opt=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper -plugin-opt=-fresolution=/tmp/ccDdzXBy.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o matlab_cpp_test /lib/../lib64/crt1.o /lib/../lib64/crti.o /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtbegin.o -L/home/matlab/lnx_x64/R2017B/release/lib -L/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7 -L/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../.. /tmp/ccsqA2N9.o -lpthread -lMatlabEngine -lstdc++ -v -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/crtend.o /lib/../lib64/crtn.o
GNU ld version 2.28-11.el7
/home/matlb/lnx_x64/R2017B/release/lib/libMatlabEngine.so: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8'
collect2: error: ld returned 1 exit status

I checked the error message in some other SO questions like this. According to the answer, I am linking against the wrong version of libstdc++. But when I check my LD_LIBRARY_PATH variable, it contains the path for the new libstdc++.so at the beginning:

[giant@centos-machine test]$ echo $LD_LIBRARY_PATH
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7:/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib:/opt/rh/devtoolset-7/root/usr/lib64/dyninst:/opt/rh/devtoolset-7/root/usr/lib/dyninst:/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib

Can anyone give me some pointers how I should fix this issue?

TonySalimi
  • 8,257
  • 4
  • 33
  • 62
  • 1
    Don't you need to use the same version of `libstdc++` that the Matlab API expects? `CXXABI_1.3.8` is the version that corresponds to the c++ runtimes that come with the GCC 4.9 compiler. – Mansoor Sep 27 '21 at 09:04
  • How did you compile `libMatlabEngine.so` ?? – nhatnq Sep 27 '21 at 09:59
  • @Mansoor But my current `libstdc++` is coming with gcc 7.3.1 that is newer the one expected. I assume that forward compatibility is supported in all versions of gcc libs. Am I right? – TonySalimi Sep 27 '21 at 11:57
  • @nhatnq According to the documentation of Matlab, ([check here](https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/support/sysreq/files/SystemRequirements-Release2017b_SupportedCompilers.pdf)), it has been built with gcc 4.9. – TonySalimi Sep 27 '21 at 11:59
  • 1
    devtoolset-7 : `/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libstdc++.so` is a 210B text file : "/usr/lib64/libstdc++.so.6" will be used. ............ Extra gcc/g++, EL7 https://stackoverflow.com/questions/47175706/how-to-install-gcc-4-9-2-on-rhel-7-4/47189915#47189915 – Knud Larsen Sep 27 '21 at 12:09
  • @KnudLarsen Oh, so according to this fact, where is the most recent `libstdc++` located? – TonySalimi Sep 27 '21 at 12:24
  • @KnudLarsen but my `/usr/lib64/libstdc++.so.6` refers to `libstdc++.so.6.0.19`, that comes from gcc 4.8.5 (the original distribution) – TonySalimi Sep 27 '21 at 15:03
  • @KnudLarsen I have already downloaded and installed gcc 7.3.1, but as you mentioned, the only `libstdc++.so` file available inside it, is a text file !!! – TonySalimi Sep 27 '21 at 15:14
  • Repeat : Please read https://stackoverflow.com/questions/47175706/how-to-install-gcc-4-9-2-on-rhel-7-4/47189915#47189915 – Knud Larsen Sep 27 '21 at 15:17

1 Answers1

1

/opt/rh/devtoolset-7

devtoolset-7 :

/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libstdc++.so

...... is a 210B text file :

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf64-x86-64)
INPUT ( /usr/lib64/libstdc++.so.6 -lstdc++_nonshared )

/usr/lib64/libstdc++.so.6 will be used.


"Other extra gcc/g++" for EL7 : how to install gcc 4.9.2 on RHEL 7.4

Knud Larsen
  • 5,753
  • 2
  • 14
  • 19