Most of the previous projects are used in Java, and their own C + +, wait until the online time to discover the online machine gcc and libc versions are very low, with their own test development environment incompatible, compiled C + + executable file can not run. Solving the porting of C + + programs It's a lot of trouble, as follows is a specific record:
1, the problem description
As mentioned above, the online machine and the development machine environment is incompatible, need to do C + + program porting.
2, performance
The details are not table, in short, the program can not run, can not find the corresponding library. Here are a couple of gcc-related error tips:
/usr/lib64/libstdc++.so.6:version ' glibcxx_3.4.9 ' not found
/lib64/libc.so.6:version ' glibc_2.7 ' not found
Wait a minute
3, tried the method
The use of static compilation on the development machine can solve most of the problems, such as thrift, CGI, Redis and other related libraries using static compilation, online machines do not have to install the corresponding software can run the program. In this way, the normal idea is that the GCC-related libraries are also statically compiled into the executable file, then the online machine can run directly, the idea is good, but we tried for a long time, or failed, online environment still can not run.
4, must not do
The painful lesson, must not casually move the line machine the libc and so on environment, especially does not move the kernel/lib64/ libc.so.6 Symbolic Link (I was so hot that I copied some of the error library files from the developer to the online machine, then change the symbolic link on the online machine library file, resulting in a big problem, or hastily upgrade the LIBC (also the lesson) of the online machine, which will cause the system to drop directly because the kernel interacts with the user state a lot. are dependent on the LIBC library, the upgrade is not compatible with the kernel, it will cause the basic LS, sudo, etc. can not be implemented. Unable to enter sudo permissions, you cannot restore the library files that have been changed or upgraded under/LIB64, and can only reboot into emergency mode, which is fatal to the machine running the wired service. If you change a soft connection such as libc.so.6 or blindly upgrade libc, the following error will be reported when executing the basic command:
Error while loading shared libraries:/lib64/libc.so.6:elf file OS ABI Invalid
More Wonderful content: http://www.bianceng.cn/Programming/cplus/
This is that although the old libc library can be loaded via ld_preload=/lib64/libc-2.5.so ls, some simple commands are executed, but sudo can't get in. So be sure to remind people not to do this on the computer online.
5, the Final Solution
1) on-line machine configuration:
You can set up a folder $dir/mylib64 in the user directory, and $dir represent the absolute path of the folder for the following purposes. folder in the development machine under the/lib64/folder gcc corresponding library files, such as the following:
2 Development Machine Compilation options:
At the end of the g++ compilation option at the developer makefile, add the following options to specify the priority search path and dynamic linker for the dynamic library:
-WL,--rpath= $dir/lib64-wl,--dynamic-linker= $dir/lib64/ld-linux-x86-64.so.2
Where $dir is the absolute path in 1).
This allows the developer to make an executable file that can be run on the machine online.