skip to Main Content

I’ve C++ application which runs on CentOS Linux 6.6, this machine contains two GCC with versions 4.4.7 and 4.9.3.

I started to use Mozilla SpiderMonkey JS engine 60, in which I need to convert some of my std::string to std::u16string, I used the way they provide in their examples:

static inline std::u16string StringtoU16(const std::string &str) {
    std::u16string wstr = u"";
    char16_t c16str[3] = u"";
    mbstate_t mbs;
    for (const auto& it : str) {
        memset(&mbs, 0, sizeof (mbs)); //set shift state to the initial state
        memmove(c16str, u"", 3);
        mbrtoc16(c16str, &it, 3, &mbs);
        wstr.append(std::u16string(c16str));
    }//for
    return wstr;
}

However, when I started to build the application on the previously mentioned environment, I found that the <uchar.h> is not found.

But when I built it on my PC using GCC 6.3.0, the code works fine.

I searched for other methods to do the conversion Convert between string, u16string & u32string but also It worked fine on my machine but on the application machine I got <codecvt> is not found.

I tried to take the output of building the application on my PC (GCC 6.3.0) and run it on the application machine (CentOS 6.6) using the following procedure:

  1. Copied the libstdc++.so.6.0.22 to CentOS machine
  2. Updated the LD_LIBRARY_PATH
  3. Started the application

But I got that libstdc++ needs libc.so.6. I stopped here because when I copied it, it needs another library.

So, what is the Solution? Is there any way to compile on my PC and run on the app machine?

2

Answers


  1. The old GCC versions on your CentOS machine do not support the C++11 features you’re trying to use.

    The solution I would recommend is to install the devtoolset-8-gcc-c++ package from the Developer Toolset in Software Collections (see https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/ for instructions on setting that up — the process is the same for devtoolset-8-gcc as for devtoolset-7-gcc).

    That will install a newer GCC that can be used to compile C++11 code on the CentOS machine, producing binaries which will run on the old CentOS system without requiring any new runtime libraries.

    Login or Signup to reply.
  2. Another solution (if Jonathan one‘s don’t work) is to learn how to build GCC (Gnu Compiler Collection) -i.e. several compilers- and install it from its source code.


    I’ve got some C++ application which runs on CentOS Linux 6.6, this machine contains two GCC with versions 4.4.7 and 4.9.3.

    Notice that both GCC 4.4 and 4.9 are obsolete and unmaintained by the FSF.


    First, a successful build of GCC from its source code takes quite a lot of time (and a few gigabytes of disk space). Perhaps a few hours of (mostly CPU) time on a quite powerful PC (you may need at least 32 gigabytes of RAM, because a straight (non cross) GCC compiler is bootstrapped and uses LTO).

    There are pro and cons to this approach. The pro is immediate: once you have learned how to compile GCC from its source code, you could get the latest release (GCC 9 in july 2019) as soon as it is published, and that release is likely to support most of the latest C++ language standards (and several new ones, like Go or D) and increasingly fancy optimizations targeting recent processors (maybe dynamically your current one). The cons includes learning the configuration procedure (quite a complex one, since GCC has many tunable features, bells and whistles) and of course waiting several hours for the build to complete.

    So you need to make a trade-off. Are you willing to spend a few hours in learning how to build GCC, or not.

    The configuration of an installed GCC is obtained with gcc -v (or gcc-8 -v if your GCC was configured installed as gcc-8 ….) and could inspire the configuration of a newly downloaded GCC.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search