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?