std::map where type of key is struct #std


Leo
 

Hello all,
I am trying to create an std::map where type of key is struct and I provide my own comparator.
The code compiles/executes correctly with g++ (click on links below) outside of the Zephyr environment but fails otherwise.
Am I missing some CONFIG_ statements in prj.conf? How do I fix this issue?
Thanks,
Leo

All of these work with g++:
    User-defined comparator:
        http://cpp.sh/8esou

    Template specialization:
        http://cpp.sh/7cslu

    Operator overloading:
        http://cpp.sh/4r3yw

None of the above work with Zephyr:
    main.cpp (user-defined comparator):
        #include <sys/printk.h>
        #include <map>
       
        struct Data {
            int index;
        };
       
        struct Comparator {
            bool operator() (const Data& first, const Data& second) const {
                return first.index < second.index;
            }
        };
       
        int main() {
            std::map<Data, int, Comparator> container;
            container[Data {0}] = 0;
            container[Data {0}] = 1;
            printk("%s\n", container.find(Data {0}) == container.end() ? "not found" : "found");
            return 0;
        }
       
    ZEPHYR_TOOLCHAIN_VARIANT:
        gnuarmemb
       
    gnuarmemb version:
        7-2018-q2-update

    prj.conf:
        CONFIG_NEWLIB_LIBC=y
        CONFIG_PRINTK=y
        CONFIG_STDOUT_CONSOLE=y
        CONFIG_CPLUSPLUS=y
        CONFIG_STD_CPP17=y
   
    compilation:
        west build -p auto -b nrf52840_pca10056 std_test
       
errors:
************
In function `std::_Rb_tree<Data, std::pair<Data const, int>, std::_Select1st<std::pair<Data const, int> >, Comparator, std::allocator<std::pair<Data const, int> > >::_M_get_insert_unique_pos(Data const&)':
arm-none-eabi/include/c++/7.3.1/bits/stl_tree.h:302: undefined reference to `std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
app/libapp.a(main.cpp.obj): In function `std::map<Data, int, Comparator, std::allocator<std::pair<Data const, int> > >::operator[](Data&&)':
arm-none-eabi/include/c++/7.3.1/bits/stl_tree.h:2304: undefined reference to `std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
arm-none-eabi/include/c++/7.3.1/bits/stl_tree.h:302: undefined reference to `std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
arm-none-eabi/include/c++/7.3.1/bits/stl_tree.h:287: undefined reference to `std::_Rb_tree_increment(std::_Rb_tree_node_base*)'
collect2.exe: error: ld returned 1 exit status
%
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'cmake.EXE' --build 'build'
************

Join users@lists.zephyrproject.org to automatically receive all group messages.