Search code examples
c++compiler-errorsg++hazelcast

How can I compile Hazelcast C++ Client with the compiler g++-8.2


Is there any solution to make compilation with g++-8.2 for the project using Hazelcast C++ client library ?

If I compile it with g++-8.2, it shows a lot of errors "undefined reference ...".

While using g++-4.9, it works well.

The issue is a bit like the discussion in this google group forum, which indicated the compilation errors are because of the wrong version of a compiler.

However, the compiler g++-4.9 is too old for me to build my big project.

The sample code can be found in the official org website, if someone needs to give it a try.


Solution

  • I finally solved it by upgrading the library from 3.10 to 3.11. The 3.11 library is built manually using g++-8.2 from Hazelcast source code in Github.

    Because there is no make install after building hazelcast-cpp-clienet package, so I use some scripts to arrange header files together in one directory (hazelcast-cpp-client/include) so that a program can easily link the library and headers.

    Build script:

    #!/bin/bash
    
    # Package Requirements:
    #   - asio
    
    mkdir hazelcast-cpp-client ; cd hazelcast-cpp-client
    
    # Build
    git clone https://github.com/hazelcast/hazelcast-cpp-client.git
    mv hazelcast-cpp-client tmp
    cd tmp
    git checkout v3.11
    mkdir release ; cd release
    cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=Release ..
    make
    
    
    # Back to 'hazelcast-cpp-client' directory
    cd ../..
    
    # Copy .a library out from tmp/
    cp tmp/release/*.a .
    
    # Arrange all header files in an one directory  
    cp -r tmp/hazelcast/include .
    cp -r tmp/hazelcast/generated-sources/include/hazelcast/client/protocol ./include/hazelcast/client
    rm tmp/external/include/*.md # We don't need readme file
    cp -r tmp/external/include/* ./include
    
    # Delete tmp directory
    rm -rf tmp
    

    Compilation command is like:

    g++ -std=c++11 \
        -I/path/to/hazelcast-cpp-client/include \
        hz_test.cpp \
        /path/to/hazelcast-cpp-client/libHazelcastClient3.11_64.a \
        -lpthread