I want to compile a program by entering through SSH
the computer at my institution. I want to compile this program by using a different version of gcc
and g++
, namely a more recent one with repsect to the default installed one. This means that instead of using gcc-4.9.2
and g++-4.9.2
I would like to use gcc-6.3
and g++-6.3
. I can find them already on my computer, in fact I have the folder /opt/gcc-6.3
, so I don't have to download them. So what I do is the following
export PATH=/opt/gcc-6.3/bin/:$PATH
export LD_LIBRARY_PATH=/opt/gcc-6.3/lib/:$LD_LIBRARY_PATH
but while gcc
seems to work, when I try to compile a c++
program with g++
I get
./[name_of_the_program].x: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./[name_of_the_program].x)
./[name_of_the_program].x: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./[name_of_the_program].x)
Obviously, if that's relevant information, I am not root
on this machine.
If you are running on a 64bit machine, you must add
/opt/linux-gnu_6.x.x/lib64
path also to you environment. ( or which path on your machine is used for the libs of this compiler version )
If you get root access you should better add ( or maybe your admin should do! ) your library path information to
/etc/ld.so.conf.d/gcc63.conf
and run sudo ldconfig
.
After that you should check with ldd
comand, that all chained requirements are fulfilled.
Don't do this:
export PATH=/opt/gcc-6.3/bin/:$PATH
export LD_LIBRARY_PATH=/opt/gcc-6.3/lib/:$LD_LIBRARY_PATH
Instead, add:
-B/opt/gcc-6.3/lib/
to your invocation options for either of the frontends gcc
or g++
(assuming that /opt/gcc-6.3/lib/
is indeed the directory that directly contains the GCC 6.3 toolchain executables and libraries).
See the documentation of the -Bprefix option
Example:
$ cat prog.cpp
#include <iostream>
int main()
{
std::cout << "I was compiled with GCC "
<< __GNUC__ << '.' << __GNUC_MINOR__ << '.' << __GNUC_PATCHLEVEL__
<< " to C++ standard " << __cplusplus << std::endl;
return 0;
}
$ which g++-4.9
/usr/bin/g++-4.9
$ which g++-6
/usr/bin/g++-6
$ g++-4.9 -o prog prog.cpp && ./prog
I was compiled with GCC 4.9.4 to C++ standard 199711
$ g++-4.9 -B/usr/lib/gcc/x86_64-linux-gnu/6.2.0 -o prog prog.cpp && ./prog
I was compiled with GCC 6.2.0 to C++ standard 201402
As per others' comments, be aware g++ >= 5 is ABI incompatible with g++
< 5.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.