Click here to Skip to main content
15,611,549 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to compile a C++ tomography code on RH7. I have previously compiled it on Ubuntu 20.04 with some issues that were easily solved by adding missing includes on the original code.

I have limited experience with C++ and I'm still not confident enough to pretend that I fully understand the architecture of this code.

This code depends on boost >1.62 and I have compiled boost 1.79.0 with MPI support.

Right now, I'm struggling with a compilation error:

[  3%] Building CXX object CMakeFiles/tomo3d.dir/axb_solver.cpp.o
[  6%] Building CXX object CMakeFiles/tomo3d.dir/in_house_solver.cpp.o
[ 10%] Building CXX object CMakeFiles/tomo3d.dir/in_house_omp_solver.cpp.o
In file included from /usr/include/c++/4.8.2/ext/alloc_traits.h:36:0,
                 from /usr/include/c++/4.8.2/bits/stl_construct.h:61,
                 from /usr/include/c++/4.8.2/bits/stl_tempbuf.h:60,
                 from /usr/include/c++/4.8.2/bits/stl_algo.h:62,
                 from /usr/include/c++/4.8.2/algorithm:62,
                 from /home/aloureiro/tomo3D/tt_inverse3d/in_house_omp_solver.cpp:9:
/usr/include/c++/4.8.2/bits/alloc_traits.h: In instantiation of ‘void std::__alloc_on_move(_Alloc&, _Alloc&) [with _Alloc = boost::alignment::aligned_allocator<double, 1ul>]’:
/usr/include/c++/4.8.2/bits/stl_vector.h:1369:36:   required from ‘void std::vector<_Tp, _Alloc>::_M_move_assign(std::vector<_Tp, _Alloc>&&, std::true_type) [with _Tp = double; _Alloc = boost::alignment::aligned_allocator<double, 1ul>; std::true_type = std::integral_constant<bool, true>]’
/usr/include/c++/4.8.2/bits/stl_vector.h:445:65:   required from ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = double; _Alloc = boost::alignment::aligned_allocator<double, 1ul>]’
/home/aloureiro/tomo3D/tt_inverse3d/in_house_omp_solver.cpp:88:15:   required from here
/usr/include/c++/4.8.2/bits/alloc_traits.h:490:49: error: no matching function for call to ‘__do_alloc_on_move(boost::alignment::aligned_allocator<double, 1ul>&, boost::alignment::aligned_allocator<double, 1ul>&, __pocma)’
       __do_alloc_on_move(__one, __two, __pocma());
/usr/include/c++/4.8.2/bits/alloc_traits.h:490:49: note: candidates are:
/usr/include/c++/4.8.2/bits/alloc_traits.h:478:17: note: template<class _Alloc> void std::__do_alloc_on_move(_Alloc&, _Alloc&, std::true_type)
     inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two, true_type)
/usr/include/c++/4.8.2/bits/alloc_traits.h:478:17: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8.2/bits/alloc_traits.h:490:49: note:   cannot convert ‘__pocma()’ (type ‘__pocma {aka boost::alignment::detail::integral_constant<bool, true>}’) to type ‘std::true_type {aka std::integral_constant<bool, true>}’
       __do_alloc_on_move(__one, __two, __pocma());
/usr/include/c++/4.8.2/bits/alloc_traits.h:482:17: note: template<class _Alloc> void std::__do_alloc_on_move(_Alloc&, _Alloc&, std::false_type)
     inline void __do_alloc_on_move(_Alloc&, _Alloc&, false_type)
/usr/include/c++/4.8.2/bits/alloc_traits.h:482:17: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8.2/bits/alloc_traits.h:490:49: note:   cannot convert ‘__pocma()’ (type ‘__pocma {aka boost::alignment::detail::integral_constant<bool, true>}’) to type ‘std::false_type {aka std::integral_constant<bool, false>}’
       __do_alloc_on_move(__one, __two, __pocma());
make[2]: *** [CMakeFiles/tomo3d.dir/in_house_omp_solver.cpp.o] Error 1
make[1]: *** [CMakeFiles/tomo3d.dir/all] Error 2
make: *** [all] Error 2

The offending line:
in_house_omp_solver.cpp:88:15:  v = mat.omp_mul_transposed(u); 

This refers to sparse_rect.hpp:
class SparseRectangular : private SparseRectangularData {
    typedef SparseRectangularData super;
    using super::super;
    ~SparseRectangular() {};

    int nRow() const { return nrow; }
    int nCol() const { return ncol; }
    void Ax (std::vector<double> const&, std::vector<double>&, bool init = true) const;
    void omp_mul(aligned_vector<double> const& b, aligned_vector<double>& x, bool init = true) const;
    aligned_vector<double> omp_mul(aligned_vector<double> const& b) const;
    void omp_mul_transposed(aligned_vector<double> const& b, aligned_vector<double>& x, bool init = true) const;
    aligned_vector<double> omp_mul_transposed(aligned_vector<double> const& b) const;
    void Atx(std::vector<double> const&, std::vector<double>&, bool init = true) const;
    void dump(const char* fname = 0) const;

    SparseRectangularData const& raw() const { return *this; }

    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
        // serialize base class information
        ar & boost::serialization::base_object<SparseRectangularData>(*this);

I'm quite lost here. On a different machine, I had compilation errors but they were due to missing include declarations and an unused logging routine.

What I have tried:

On the workstation where I successfully compiled this code, I used boost 1.78.0 and gcc 9.3. On this machine I am limited to gcc 4.8.

I have tried to follow the compilation error backwards but got nowhere.

I don't find anything suspicious on the code I'm compiling. It has been compiled before on different machines. Could this be related to the compiler version?
Updated 13-May-22 1:57am

Could this be related to the compiler version?
That's quite probable. You might be able to solve it by trying different standard compliance versions. GCC 4.8 compiles by default as C++ 98, you could try setting -std=c++11 for the compile and see if that helps. To do that, you will need probably need to re-run <configure> to set the C++ compiler flags. Normally this is something like
[user@host]$ CXXFLAGS=-std=c++11 ./configure # ... other flags ...
You'll have to consult the build instructions to find out exactly how to do that
Alternatively, you could try using clang++ instead of g++, but CentOS 7 only supplies clang 3.4.2, which also only supports c++11.

As you have access to a g++, you can always build a newer version of the compiler. I have successfully built g++ 12-1.0 for CentOS 7. There are several things to be aware of:
* You may need to download newer versions of mpfr, mpc and gmp. I always download the newest version of these when building a new compiler, and have them built as part of the compiler build. You may be able to get away with just adding the relevant devel packages to your CentOS 7 instance.
* If you do not have admin access, you will need to set things up to install somewhere you do have access - e.g. your home directory. That's achieved by adding --prefix=$HOME to the config arguments when building gcc.
* compilation of g++ requires about 4-5 G of disk space. There are options to configure to reduce the space requirement, but its something you should be aware of before you start.
* Expect compilation to take anywhere from 30 minutes to several hours, depending on your CPU. Things can be improved by telling make to use more than one core to compile e.g. make -j$(nproc) will use all available threads to compile.
* C++ code compiled with the new compiler will need to know where to find the appropriate libstdc++. If you don't mind larger executables, you can add -static-libstdc++ to the link flags for your project. This removes the requirement for executables to know where the g++-12 specific libraries are. Otherwise, you'll have to look at using something like LD_LIBRARY_PATH or using -rpath when linking. If you need to distribute the executables elswhere, I'd suggest using the static libstdc++ as this means you do not have to distribute libstdc++ along with your project.

It's also possible that your version of boost is too old. You may need to update both boost and the compiler. Most of what I've said about the compiler also applies to boost, but I'm not sure if boost will create static libraries when you build, which may be a deal breaker.

Everything you need to know about building g++ is available here Installing GCC- GNU Project[^]
Instructions for building boost are here: Boost Getting Started on Unix Variants - 1.63.0[^]
Share this answer
AVLoureiro 11-May-22 11:52am    
First of all, thank you for taking your time to help me.

I have the latest version of Boost, and I compiled it with CXXFLAGS=-std=c++11

I don't have admin access, but there seems to be a newer gcc version already compiled on this HPC. I'll try to compile Boost with this version and then the tomography code.

I can also try to statically-compile the program on another machine and test if it works with the MPI on this machine.

If this fails, I'll compile g++ and proceed from there.

Thank you again.
After a few days, I managed to solve this problem.

I configured cmake to use another version of g++ available on the system:
-DCMAKE_C_COMPILER=/share/apps/gcc/v7.3.0/bin/gcc -DCMAKE_CXX_COMPILER=/share/apps/gcc/v7.3.0/bin/g++

This allowed me to compile without errors. But the executable was unable to find the newer version libraries:
./tt_inverse3d: /lib64/ version `GLIBCXX_3.4.20' not found (required by ./tt_inverse3d)
./tt_inverse3d: /lib64/ version `GLIBCXX_3.4.22' not found (required by ./tt_inverse3d)
./tt_inverse3d: /lib64/ version `CXXABI_1.3.9' not found (required by ./tt_inverse3d)
./tt_inverse3d: /lib64/ version `GLIBCXX_3.4.21' not found (required by ./tt_inverse3d)

The easiest solution I found for this was to simply add the following to my .bashrc

Thank you for the help, k5054.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900