S7th
S7th

Reputation: 25

Cross platform compilation problem on linux: error: new_allocator.h:93:7: error: multiple overloads of 'address' instantiate to the same signature

My problem is i am developping a cli software on a mac and the final binary will execute on a linux system.

So i use a docker to compile but i have an error that doesn't seem to come from my code (since it works like a charm on mac) but you know ... I don't have enought background in cpp / tool chain to understand what cause this error on linux and what to do to solve this issue.

TLDR :

cpp_1  | [  8%] Building CXX object core-lib/CMakeFiles/core-lib.dir/controllers/MainController.cpp.o
cpp_1  | In file included from /usr/src/OF/apps/project/core-lib/controllers/MainController.cpp:8:
cpp_1  | In file included from /usr/src/OF/apps/project/core-lib/controllers/MainController.hpp:11:
cpp_1  | In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/vector:61:
cpp_1  | In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/allocator.h:46:
cpp_1  | In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/c++allocator.h:33:
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/ext/new_allocator.h:93:7: error: multiple overloads of 'address' instantiate to the same signature '__gnu_cxx::new_allocator<const ColumnState>::const_pointer (__gnu_cxx::new_allocator<const ColumnState>::const_reference) const noexcept' (aka 'const ColumnState *(const ColumnState &) const noexcept')
cpp_1  |       address(const_reference __x) const _GLIBCXX_NOEXCEPT
cpp_1  |       ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/allocator.h:108:29: note: in instantiation of template class '__gnu_cxx::new_allocator<const ColumnState>' requested here
cpp_1  |     class allocator: public __allocator_base<_Tp>
cpp_1  |                             ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:550:16: note: in instantiation of template class 'std::allocator<const ColumnState>' requested here
cpp_1  |       : public _Tp_alloc_type
cpp_1  |                ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:633:19: note: in instantiation of member class 'std::_Deque_base<const ColumnState, std::allocator<const ColumnState> >::_Deque_impl' requested here
cpp_1  |       _Deque_impl _M_impl;
cpp_1  |                   ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:831:29: note: in instantiation of template class 'std::_Deque_base<const ColumnState, std::allocator<const ColumnState> >' requested here
cpp_1  |     class deque : protected _Deque_base<_Tp, _Alloc>
cpp_1  |                             ^
cpp_1  | /usr/src/OF/apps/project/core-lib/io/AbstractInstallCommunicator.hpp:17:35: note: in instantiation of template class 'std::deque<const ColumnState, std::allocator<const ColumnState> >' requested here
cpp_1  |     std::deque<const ColumnState> states;
cpp_1  |                                   ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/ext/new_allocator.h:89:7: note: previous declaration is here
cpp_1  |       address(reference __x) const _GLIBCXX_NOEXCEPT

the CMAKE cpp config :

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

linux config :

    ubuntu bionic
    cmake --version : cmake version 3.16.5
    make --version : GNU Make 4.1
    clang --version : clang version 10.0.0-4ubuntu1~18.04.1 

mac config

    Mojave 10.14.6
    cmake --version : cmake version 3.16.3
    make --version : GNU Make 3.81
    clang --version : Apple clang version 11.0.0 (clang-1100.0.33.17)

When I compile on mac it works fine :

building
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GLM: /usr/local/include  
-- GLM_INCLUDE_DIR = /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/fyoudine/Documents/workspaces/OF/of_v20190923_osx_release/apps/project-Optics/build
Scanning dependencies of target core-lib
[  2%] Building CXX object core-lib/CMakeFiles/core-lib.dir/config/GlobalConf.cpp.o
[  5%] Building CXX object core-lib/CMakeFiles/core-lib.dir/controllers/LightManager.cpp.o
[  8%] Building CXX object core-lib/CMakeFiles/core-lib.dir/controllers/MainController.cpp.o
[ 11%] Building CXX object core-lib/CMakeFiles/core-lib.dir/d3/Object3D.cpp.o
[ 14%] Building CXX object core-lib/CMakeFiles/core-lib.dir/d3/Object3DChild.cpp.o
[ 17%] Building CXX object core-lib/CMakeFiles/core-lib.dir/install/AbstractInstall.cpp.o
[ 20%] Building CXX object core-lib/CMakeFiles/core-lib.dir/install/FileConfigurationInstall.cpp.o
[ 22%] Building CXX object core-lib/CMakeFiles/core-lib.dir/install/KineticInstall.cpp.o
[ 25%] Building CXX object core-lib/CMakeFiles/core-lib.dir/io/DMXCommunicator.cpp.o
[ 28%] Building CXX object core-lib/CMakeFiles/core-lib.dir/io/SimulatorInstallCommunicator.cpp.o
[ 31%] Building CXX object core-lib/CMakeFiles/core-lib.dir/positions/PositionSummaryMap.cpp.o
[ 34%] Building CXX object core-lib/CMakeFiles/core-lib.dir/positions/SimpleOptimalPositionFinder.cpp.o
[ 37%] Building CXX object core-lib/CMakeFiles/core-lib.dir/provider/SimpleAnimationProvider.cpp.o
[ 40%] Building CXX object core-lib/CMakeFiles/core-lib.dir/raytracing/Prism.cpp.o
[ 42%] Building CXX object core-lib/CMakeFiles/core-lib.dir/raytracing/Ray/AABB.cpp.o
[ 45%] Building CXX object core-lib/CMakeFiles/core-lib.dir/raytracing/Ray/Base.cpp.o
[ 48%] Building CXX object core-lib/CMakeFiles/core-lib.dir/raytracing/Ray/Plane.cpp.o
[ 51%] Building CXX object core-lib/CMakeFiles/core-lib.dir/raytracing/Ray/Ray.cpp.o
[ 54%] Building CXX object core-lib/CMakeFiles/core-lib.dir/raytracing/RayPath.cpp.o
[ 57%] Building CXX object core-lib/CMakeFiles/core-lib.dir/simulation/Environment.cpp.o
[ 60%] Building CXX object core-lib/CMakeFiles/core-lib.dir/simulation/Simulator.cpp.o
[ 62%] Building CXX object core-lib/CMakeFiles/core-lib.dir/simulation/anim/InstallAnimator.cpp.o
[ 65%] Building CXX object core-lib/CMakeFiles/core-lib.dir/simulation/anim/TweenColumnAnimator.cpp.o
[ 68%] Building CXX object core-lib/CMakeFiles/core-lib.dir/simulation/data/RayCastResult.cpp.o
[ 71%] Building CXX object core-lib/CMakeFiles/core-lib.dir/simulation/elements/ColumnData.cpp.o
[ 74%] Building CXX object core-lib/CMakeFiles/core-lib.dir/simulation/elements/Light.cpp.o
[ 77%] Building CXX object core-lib/CMakeFiles/core-lib.dir/simulation/elements/PrismData.cpp.o
[ 80%] Building CXX object core-lib/CMakeFiles/core-lib.dir/states/ColumnState.cpp.o
[ 82%] Building CXX object core-lib/CMakeFiles/core-lib.dir/states/InstallState.cpp.o
[ 85%] Building CXX object core-lib/CMakeFiles/core-lib.dir/utils/calculateSunPosition.cpp.o
[ 88%] Building CXX object core-lib/CMakeFiles/core-lib.dir/utils/spa.cpp.o
[ 91%] Building CXX object core-lib/CMakeFiles/core-lib.dir/utils/vec_color.cpp.o
[ 94%] Linking CXX static library ../libs/libcore-lib.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../libs/libcore-lib.a(InstallAnimator.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../libs/libcore-lib.a(InstallAnimator.cpp.o) has no symbols
[ 94%] Built target core-lib
Scanning dependencies of target project-cli
[ 97%] Building CXX object project-cli/CMakeFiles/project-cli.dir/main.cpp.o
[100%] Linking CXX executable ../../bin/project-cli
[100%] Built target project-cli

But when I compile for linux via docker :

starting docker_cpp_1 ... done
Attaching to docker_cpp_1
cpp_1  | building
cpp_1  | -- The C compiler identification is Clang 10.0.0
cpp_1  | -- The CXX compiler identification is Clang 10.0.0
cpp_1  | -- Check for working C compiler: /usr/bin/clang-10
cpp_1  | -- Check for working C compiler: /usr/bin/clang-10 -- works
cpp_1  | -- Detecting C compiler ABI info
cpp_1  | -- Detecting C compiler ABI info - done
cpp_1  | -- Detecting C compile features
cpp_1  | -- Detecting C compile features - done
cpp_1  | -- Check for working CXX compiler: /usr/bin/clang++-10
cpp_1  | -- Check for working CXX compiler: /usr/bin/clang++-10 -- works
cpp_1  | -- Detecting CXX compiler ABI info
cpp_1  | -- Detecting CXX compiler ABI info - done
cpp_1  | -- Detecting CXX compile features
cpp_1  | -- Detecting CXX compile features - done
cpp_1  | -- Found GLM: /usr/include  
cpp_1  | -- GLM_INCLUDE_DIR = /usr/include
cpp_1  | -- Configuring done
cpp_1  | -- Generating done
cpp_1  | -- Build files have been written to: /usr/src/OF/apps/project/build
cpp_1  | Scanning dependencies of target core-lib
cpp_1  | [  2%] Building CXX object core-lib/CMakeFiles/core-lib.dir/config/GlobalConf.cpp.o
cpp_1  | [  5%] Building CXX object core-lib/CMakeFiles/core-lib.dir/controllers/LightManager.cpp.o
cpp_1  | [  8%] Building CXX object core-lib/CMakeFiles/core-lib.dir/controllers/MainController.cpp.o
cpp_1  | In file included from /usr/src/OF/apps/project/core-lib/controllers/MainController.cpp:8:
cpp_1  | In file included from /usr/src/OF/apps/project/core-lib/controllers/MainController.hpp:11:
cpp_1  | In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/vector:61:
cpp_1  | In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/allocator.h:46:
cpp_1  | In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/c++allocator.h:33:
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/ext/new_allocator.h:93:7: error: multiple overloads of 'address' instantiate to the same signature '__gnu_cxx::new_allocator<const ColumnState>::const_pointer (__gnu_cxx::new_allocator<const ColumnState>::const_reference) const noexcept' (aka 'const ColumnState *(const ColumnState &) const noexcept')
cpp_1  |       address(const_reference __x) const _GLIBCXX_NOEXCEPT
cpp_1  |       ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/allocator.h:108:29: note: in instantiation of template class '__gnu_cxx::new_allocator<const ColumnState>' requested here
cpp_1  |     class allocator: public __allocator_base<_Tp>
cpp_1  |                             ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:550:16: note: in instantiation of template class 'std::allocator<const ColumnState>' requested here
cpp_1  |       : public _Tp_alloc_type
cpp_1  |                ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:633:19: note: in instantiation of member class 'std::_Deque_base<const ColumnState, std::allocator<const ColumnState> >::_Deque_impl' requested here
cpp_1  |       _Deque_impl _M_impl;
cpp_1  |                   ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:831:29: note: in instantiation of template class 'std::_Deque_base<const ColumnState, std::allocator<const ColumnState> >' requested here
cpp_1  |     class deque : protected _Deque_base<_Tp, _Alloc>
cpp_1  |                             ^
cpp_1  | /usr/src/OF/apps/project/core-lib/io/AbstractInstallCommunicator.hpp:17:35: note: in instantiation of template class 'std::deque<const ColumnState, std::allocator<const ColumnState> >' requested here
cpp_1  |     std::deque<const ColumnState> states;
cpp_1  |                                   ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/ext/new_allocator.h:89:7: note: previous declaration is here
cpp_1  |       address(reference __x) const _GLIBCXX_NOEXCEPT
cpp_1  |       ^
cpp_1  | In file included from /usr/src/OF/apps/project/core-lib/controllers/MainController.cpp:8:
cpp_1  | In file included from /usr/src/OF/apps/project/core-lib/controllers/MainController.hpp:16:
cpp_1  | In file included from /usr/src/OF/apps/project/core-lib/install/AbstractInstall.hpp:11:
cpp_1  | In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/deque:64:
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:843:31: error: '_Tp_alloc_type' is a protected member of 'std::_Deque_base<const ColumnState, std::allocator<const ColumnState> >'
cpp_1  |       typedef typename _Base::_Tp_alloc_type            _Tp_alloc_type;
cpp_1  |                               ^
cpp_1  | /usr/src/OF/apps/project/core-lib/io/AbstractInstallCommunicator.hpp:17:35: note: in instantiation of template class 'std::deque<const ColumnState, std::allocator<const ColumnState> >' requested here
cpp_1  |     std::deque<const ColumnState> states;
cpp_1  |                                   ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:464:21: note: declared protected here
cpp_1  |         rebind<_Tp>::other _Tp_alloc_type;
cpp_1  |                            ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:844:31: error: '_Alloc_traits' is a protected member of 'std::_Deque_base<const ColumnState, std::allocator<const ColumnState> >'
cpp_1  |       typedef typename _Base::_Alloc_traits             _Alloc_traits;
cpp_1  |                               ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:465:58: note: declared protected here
cpp_1  |       typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type>  _Alloc_traits;
cpp_1  |                                                          ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:845:31: error: '_Map_pointer' is a protected member of 'std::_Deque_base<const ColumnState, std::allocator<const ColumnState> >'
cpp_1  |       typedef typename _Base::_Map_pointer              _Map_pointer;
cpp_1  |                               ^
cpp_1  | /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_deque.h:544:47: note: declared protected here
cpp_1  |       typedef typename iterator::_Map_pointer _Map_pointer;
cpp_1  |                                               ^
cpp_1  | 4 errors generated.
cpp_1  | make[2]: *** [core-lib/CMakeFiles/core-lib.dir/controllers/MainController.cpp.o] Error 1
cpp_1  | core-lib/CMakeFiles/core-lib.dir/build.make:88: recipe for target 'core-lib/CMakeFiles/core-lib.dir/controllers/MainController.cpp.o' failed
cpp_1  | make[1]: *** [core-lib/CMakeFiles/core-lib.dir/all] Error 2
cpp_1  | CMakeFiles/Makefile2:114: recipe for target 'core-lib/CMakeFiles/core-lib.dir/all' failed
cpp_1  | make: *** [all] Error 2
cpp_1  | Makefile:83: recipe for target 'all' failed
docker_cpp_1 exited with code 2

both are compiled with the same command :

cmake .. && make

Upvotes: 0

Views: 863

Answers (1)

Rudolfs Bundulis
Rudolfs Bundulis

Reputation: 11944

The error itself comes from the definition of std::deque<const ColumnState> states. Until C+11 the element types of std::deque had to be CopyAssignable and CopyConstructible (thus can't be const qualified as in you code) - see std::deque.

After C+11 the constraints are actually imposed by the operations done on the deque:

The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements.

So without seeing the code that manipulates states it is hard to see what exactly triggers this. A trivial workaround (if the context allows it) is to remove the const there. Of course, both compilers should behave the same (if they both honor c++17 and there actually is an operation on the variable which violates the constness), but if you just need a quick fix this could do.

Upvotes: 1

Related Questions